Skip to content

Commit

Permalink
update to rcompat 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Jun 3, 2024
1 parent 7f1b2c4 commit 39f48fd
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"directory": "packages/binding"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"peerDependencies": {
"@ruby/head-wasm-wasi": "2",
Expand Down
10 changes: 2 additions & 8 deletions packages/binding/src/bindings/common/peers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { File } from "rcompat/fs";
import { manifest } from "rcompat/package";

const up = 4;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).peerDependencies,
};
export default { ...(await manifest(import.meta.filename)).peerDependencies };
6 changes: 3 additions & 3 deletions packages/binding/src/bindings/depend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { File } from "rcompat/fs";
import { packager, manifest } from "rcompat/meta";
import * as P from "rcompat/package";
import { packager } from "rcompat/meta";
import errors from "../errors.js";

const semver_regexp = /^\^?(?<integer>\d+)\.?(?<float>.*)$/gu;
Expand All @@ -20,7 +20,7 @@ const find_dependencies = (target, current) =>
const { MissingDependencies, UpgradeDependencies } = errors;

export default async (target_dependencies, from) => {
const { dependencies } = await (await File.root()).join(manifest).json();
const { dependencies } = await P.manifest();

const versions = find_dependencies(target_dependencies, dependencies);
if (versions.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/go/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { File } from "rcompat/fs";
import { upperfirst } from "rcompat/string";
import { execute } from "rcompat/stdio";
import { user } from "rcompat/env";
import * as O from "rcompat/object";
import errors from "./errors.js";

const default_extension = ".go";
Expand Down Expand Up @@ -109,7 +110,6 @@ const create_meta_files = async (directory, types, app) => {
// copy go.sum file
await directory.join(meta.sum).write(await root.join(meta.sum).text());

const has_types = Object.keys(types).length > 0;
const supported_types = Object.entries(types)
.filter(([_, { base }]) => type_map[base] !== undefined);
const dispatch_struct = supported_types.map(([name, { base }]) =>
Expand All @@ -132,7 +132,7 @@ const create_meta_files = async (directory, types, app) => {
.text())
.replace("%%DISPATCH_STRUCT%%", _ => dispatch_struct)
.replace("%%DISPATCH_MAKE%%", _ => dispatch_make)
.replace("%%IMPORTS%%", _ => has_types ? "import \"errors\"" : "")
.replace("%%IMPORTS%%", _ => O.empty(types) ? "" : "import \"errors\"")
.replace("%%REQUEST_STRUCT%%", _ => request_struct)
.replace("%%REQUEST_MAKE%%", _ => request_make),
);
Expand Down
3 changes: 2 additions & 1 deletion packages/binding/src/bindings/ruby/exports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { File } from "rcompat/fs";
import * as P from "rcompat/package";
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/node";

const ruby_path = (await File.root())
const ruby_path = (await P.root())
.join("node_modules/@ruby/head-wasm-wasi/dist/ruby+stdlib.wasm");
const ruby_wasm = await File.arrayBuffer(ruby_path);
const module = await WebAssembly.compile(ruby_wasm);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-primate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@clack/prompts": "^0.7.0",
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"type": "module",
"devDependencies": {
Expand Down
10 changes: 2 additions & 8 deletions packages/create-primate/src/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { File } from "rcompat/fs";
import { manifest } from "rcompat/package";

const up = 2;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).devDependencies,
};
export default { ...(await manifest(import.meta.filename)).devDependencies };
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"directory": "packages/frontend"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"peerDependencies": {
"@angular/compiler": "17",
Expand Down
10 changes: 2 additions & 8 deletions packages/frontend/src/frontends/common/peers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { File } from "rcompat/fs";
import { manifest } from "rcompat/package";

const up = 4;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).peerDependencies,
};
export default { ...(await manifest(import.meta.filename)).peerDependencies };
2 changes: 1 addition & 1 deletion packages/frontend/src/frontends/htmx/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default ({
extensions.forEach(extension_name =>
app.build.export(`export * from "${htmx}/${extension_name}";`));

if (Object.keys(client_side_templates).length > 0) {
if (!O.empty(client_side_templates)) {
if (!extensions.includes(templates)) {
errors.MissingClientSideTemplateDependency.throw(templates,
client_side_templates.join(", "));
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"directory": "packages/i18n"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"peerDependencies": {
"primate": "0.31"
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dim } from "rcompat/colors";
import { Status } from "rcompat/http";
import * as O from "rcompat/object";
import errors from "./errors.js";

const {
Expand Down Expand Up @@ -63,7 +64,7 @@ export default ({
const loading = `loading ${loaded.map(l => dim(l)).join(" ")}`;
app.log.info(loading, { module });

disable(Object.keys(locales).length === 0, () => {
disable(O.empty(locales), () => {
EmptyLocaleDirectory.warn(app.log, root);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/primate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"directory": "packages/primate"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"engines": {
"node": ">=18"
Expand Down
9 changes: 5 additions & 4 deletions packages/primate/src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tryreturn } from "rcompat/async";
import crypto from "rcompat/crypto";
import { identity } from "rcompat/function";
import { File } from "rcompat/fs";
import { identity } from "rcompat/function";
import { MediaType, Status } from "rcompat/http";
import { is } from "rcompat/invariant";
import * as runtime from "rcompat/meta";
Expand Down Expand Up @@ -32,10 +32,11 @@ const load = (base, page, fallback) =>

const encoder = new TextEncoder();

const attribute = attributes => Object.keys(attributes).length > 0
? " ".concat(Object.entries(attributes)
const attribute = attributes => O.empty(attributes)
? ""
: " ".concat(Object.entries(attributes)
.map(([key, value]) => `${key}="${value}"`).join(" "))
: "";
;
const tag = (name, { attributes = {}, code = "", close = true }) =>
`<${name}${attribute(attributes)}${close ? `>${code}</${name}>` : "/>"}`;
const nctag = (name, properties) => tag(name, { ...properties, close: false });
Expand Down
14 changes: 6 additions & 8 deletions packages/primate/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { blue, bold } from "rcompat/colors";
import { File } from "rcompat/fs";
import { runtime } from "rcompat/meta";
import * as O from "rcompat/object";
import { resolve } from "rcompat/package";
import * as P from "rcompat/package";
import { default as Logger, bye, print } from "./Logger.js";
import app from "./app.js";
import find from "./commands/exports.js";
Expand All @@ -12,16 +12,15 @@ import errors from "./errors.js";
import { init } from "./hooks/exports.js";

let logger = new Logger({ level: Logger.Warn });
const config_filename = "primate.config.js";

const get_config = async root => {
const name = "primate.config.js";
const config = root.join(name);
const config = root.join(config_filename);
return await config.exists()
? tryreturn(async _ => {
const imported = await config.import("default");

(imported === undefined || Object.keys(imported).length === 0) &&
errors.EmptyConfigFile.warn(logger, config);
O.empty(imported) && errors.EmptyConfigFile.warn(logger, config);

return O.extend(defaults, imported);
}).orelse(({ message }) =>
Expand All @@ -31,11 +30,10 @@ const get_config = async root => {

export default async (command, params) => tryreturn(async _ => {
// use module root if possible, fall back to current directory
const root = await tryreturn(_ => File.root())
.orelse(_ => File.resolve());
const root = await tryreturn(_ => P.root()).orelse(_ => File.resolve());
const config = await get_config(root);
logger = new Logger(config.logger);
const primate = await resolve(import.meta.url);
const primate = await P.manifest(import.meta.url);
print(blue(bold(primate.name)), blue(primate.version), "\n");
await find(command)(await init(await app(logger, root, config)), params);
}).orelse(error => {
Expand Down
4 changes: 2 additions & 2 deletions packages/primate/src/loaders/common.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { File } from "rcompat/fs";
import { identity } from "rcompat/function";
import * as O from "rcompat/object";
import errors from "../errors.js";

const ending = ".js";

const empty = log => (objects, name, path) =>
Object.keys(objects).length === 0
&& errors.EmptyDirectory.warn(log, name, path);
O.empty(objects) && errors.EmptyDirectory.warn(log, name, path);

export default async ({
log,
Expand Down
2 changes: 1 addition & 1 deletion packages/session/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"directory": "packages/session"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"peerDependencies": {
"primate": "0.31"
Expand Down
2 changes: 1 addition & 1 deletion packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"db:surreal": "surreal start --user test --pass test"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"devDependencies": {
"@primate/types": "^0.15.0",
Expand Down
10 changes: 2 additions & 8 deletions packages/store/src/drivers/common/peers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { File } from "rcompat/fs";
import { manifest } from "rcompat/package";

const up = 4;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).peerDependencies,
};
export default { ...(await manifest(import.meta.filename)).peerDependencies };
4 changes: 1 addition & 3 deletions packages/store/src/drivers/mongodb/Facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export default class Facade {
...Object.fromEntries(projection.map(field => [field, 1])),
},
},
...Object.keys(sort).length === 0
? {}
: { sort }
...O.empty(sort) ? {} : { sort },
};
return (await this.#by(name).find(cid(criteria), $options).toArray())
.map(document => toid(document));
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default ({

app.log.info(`loading ${loaded.map(l => dim(l)).join(" ")}`, { module });

if (Object.keys(stores).length === 0) {
if (O.empty(stores)) {
EmptyStoreDirectory.warn(app.log, root);
return next(app);
}
Expand Down
9 changes: 4 additions & 5 deletions packages/store/src/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ export default (config, facade, types) => {
facade,
async validate(input) {
const result = defined(await validate({ input, types, schema, mode }));
if (Object.keys(result.errors).length > 0) {
const error = FailedDocumentValidation.new(Object.keys(result));
error.errors = result.errors;
throw error;
} else {
if (O.empty(result.errors)) {
return result.document;
}
const error = FailedDocumentValidation.new(Object.keys(result));
error.errors = result.errors;
throw error;
},
async write(input, writer) {
const document = await this.validate(input);
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"directory": "packages/types"
},
"dependencies": {
"rcompat": "^0.14.0"
"rcompat": "^0.15.0"
},
"peerDependencies": {
"primate": "0.31"
Expand Down

0 comments on commit 39f48fd

Please sign in to comment.