@sequenceholdings/orm 0.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1222,7 +1222,12 @@ async function loadNamespaceFromDir(dir, options = {}) {
1222
1222
  const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)), {
1223
1223
  interopDefault: true,
1224
1224
  fsCache: false,
1225
- ...options.ormModulePath !== void 0 ? { alias: { "@sequenceholdings/orm": options.ormModulePath } } : {}
1225
+ ...options.ormModulePath !== void 0 ? {
1226
+ alias: {
1227
+ "@sequenceholdings/orm": options.ormModulePath,
1228
+ "@sequenceholdings/orm/authoring": options.ormModulePath
1229
+ }
1230
+ } : {}
1226
1231
  });
1227
1232
  const context = beginAuthoringContext();
1228
1233
  try {
@@ -1313,7 +1318,7 @@ var manifestOperationSchema = zod.z.object({
1313
1318
  kind: zod.z.enum(["query", "mutation"]),
1314
1319
  requires: manifestRequiresSchema
1315
1320
  });
1316
- zod.z.object({
1321
+ var operationsManifestSchema = zod.z.object({
1317
1322
  manifestVersion: zod.z.literal(MANIFEST_VERSION),
1318
1323
  schemaHash: zod.z.string().min(1),
1319
1324
  opsHash: zod.z.string().regex(OP_HASH_RE),
@@ -1924,6 +1929,10 @@ var Parser = class {
1924
1929
  this.expect("rparen", "')'");
1925
1930
  return inner;
1926
1931
  }
1932
+ if (this.peekKeyword("true") || this.peekKeyword("false")) {
1933
+ const token = this.advance();
1934
+ return { kind: "literal", value: token.value === "true" };
1935
+ }
1927
1936
  if (this.peekKeyword("capability") || this.peekKeyword("role")) {
1928
1937
  const fn = this.peek().value;
1929
1938
  const node = this.parseBooleanCall(fn);
@@ -2107,6 +2116,8 @@ var PolicyCompiler = class {
2107
2116
  }
2108
2117
  compile(node, table, depth) {
2109
2118
  switch (node.kind) {
2119
+ case "literal":
2120
+ return { kind: "const", value: node.value };
2110
2121
  case "and":
2111
2122
  case "or":
2112
2123
  return { kind: node.kind, operands: node.operands.map((operand) => this.compile(operand, table, depth)) };
@@ -7298,6 +7309,8 @@ var USAGE = `usage:
7298
7309
  seq-studio orm apply [dir] -e <env> author the migration, register, apply, and refresh the generated outputs (the everyday command)
7299
7310
  seq-studio orm apply --dry-run -e <env> rehearse the migration on a copy of the environment's real data, then discard it (no real apply)
7300
7311
  seq-studio orm apply --no-create -e <env> apply only if the namespace is already registered (CI guard; never provisions a new namespace)
7312
+ seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>
7313
+ execute one named persisted operation as the signed-in caller
7301
7314
  seq-studio orm diff [dir] write/verify the committed migration standalone (--check is the offline CI gate; --allow-destructive consents; --rebase records a v1 -> v2 conversion as a verified no-op)
7302
7315
  seq-studio orm migrate-from-yaml <dir> convert a v1 YAML namespace to the v2 TypeScript format (migrations/ preserved)
7303
7316
 
@@ -7321,6 +7334,10 @@ async function runCli(argv) {
7321
7334
  console.log(USAGE);
7322
7335
  return command ? 0 : 1;
7323
7336
  }
7337
+ if (rest.includes("--help") || rest.includes("-h")) {
7338
+ console.log(USAGE);
7339
+ return 0;
7340
+ }
7324
7341
  try {
7325
7342
  switch (command) {
7326
7343
  case "init":
@@ -7358,6 +7375,8 @@ async function runCli(argv) {
7358
7375
  const dir = positional(rest) ?? ".";
7359
7376
  return await detectProjectFormat(dir) === "v2" ? await applyV2Command(rest, dir) : await applyCommand(rest);
7360
7377
  }
7378
+ case "execute":
7379
+ return await executeV2Command(rest);
7361
7380
  default:
7362
7381
  console.error(`unknown command: ${command}`);
7363
7382
  console.log(USAGE);
@@ -7368,13 +7387,14 @@ async function runCli(argv) {
7368
7387
  return 1;
7369
7388
  }
7370
7389
  }
7390
+ var NON_DEFINITION_YAML_FILES = /* @__PURE__ */ new Set(["pnpm-lock.yaml", "pnpm-workspace.yaml"]);
7371
7391
  async function detectProjectFormat(dir) {
7372
7392
  const entries = await promises.readdir(dir, { withFileTypes: true }).catch(() => {
7373
7393
  throw new OrmDefinitionError(`namespace directory not found: ${dir}`);
7374
7394
  });
7375
7395
  const hasConfig = entries.some((entry) => entry.isFile() && entry.name === NAMESPACE_CONFIG_FILE);
7376
7396
  const hasYaml = entries.some(
7377
- (entry) => entry.isFile() && DEFINITION_FILE_EXTENSIONS.some((extension) => entry.name.endsWith(extension))
7397
+ (entry) => entry.isFile() && !NON_DEFINITION_YAML_FILES.has(entry.name) && DEFINITION_FILE_EXTENSIONS.some((extension) => entry.name.endsWith(extension))
7378
7398
  );
7379
7399
  if (hasConfig && hasYaml) {
7380
7400
  throw new OrmDefinitionError(
@@ -7569,6 +7589,79 @@ async function runConsumerCodegen(dir) {
7569
7589
  console.log(`ran consumer graphql-codegen (${CODEGEN_CONFIG_FILE})`);
7570
7590
  return 0;
7571
7591
  }
7592
+ function isVariablesObject(value) {
7593
+ return value !== null && typeof value === "object" && !Array.isArray(value);
7594
+ }
7595
+ function parseExecuteArgs(rest) {
7596
+ const args = [...rest];
7597
+ const variablesIndex = args.indexOf("--variables-file");
7598
+ if (variablesIndex === -1) {
7599
+ throw new OrmDefinitionError("execute requires --variables-file <file>");
7600
+ }
7601
+ const variablesFile = args[variablesIndex + 1];
7602
+ if (!variablesFile) {
7603
+ throw new OrmDefinitionError("execute requires --variables-file <file>");
7604
+ }
7605
+ args.splice(variablesIndex, 2);
7606
+ const envIndex = args.indexOf("--env");
7607
+ if (envIndex !== -1) args.splice(envIndex, 2);
7608
+ if (args.some((arg) => arg.startsWith("-"))) {
7609
+ throw new OrmDefinitionError("execute accepts only <operation>, [dir], --variables-file, and --env");
7610
+ }
7611
+ const operation = args[0];
7612
+ if (!operation || args.length > 2) {
7613
+ throw new OrmDefinitionError("usage: seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>");
7614
+ }
7615
+ return {
7616
+ operation,
7617
+ dir: args[1] ?? ".",
7618
+ variablesFile
7619
+ };
7620
+ }
7621
+ async function readExecuteVariables(variablesFile) {
7622
+ let parsed;
7623
+ try {
7624
+ parsed = JSON.parse(await promises.readFile(path.resolve(variablesFile), "utf8"));
7625
+ } catch (error) {
7626
+ throw new OrmDefinitionError(
7627
+ `could not read JSON variables from ${variablesFile}: ${error instanceof Error ? error.message : String(error)}`
7628
+ );
7629
+ }
7630
+ if (!isVariablesObject(parsed)) {
7631
+ throw new OrmDefinitionError("--variables-file must contain a JSON object");
7632
+ }
7633
+ return parsed;
7634
+ }
7635
+ async function executeV2Command(rest) {
7636
+ const { dir, operation, variablesFile } = parseExecuteArgs(rest);
7637
+ if (await detectProjectFormat(dir) !== "v2") {
7638
+ throw new OrmDefinitionError("execute supports TypeScript ORM v2 namespaces only");
7639
+ }
7640
+ const loaded = await loadV2(dir);
7641
+ const manifestPath = path.join(dir, OPERATIONS_MANIFEST_FILE);
7642
+ let manifest;
7643
+ try {
7644
+ manifest = operationsManifestSchema.parse(JSON.parse(await promises.readFile(manifestPath, "utf8")));
7645
+ } catch (error) {
7646
+ throw new OrmDefinitionError(
7647
+ `could not read ${OPERATIONS_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)} \u2014 run \`seq-studio orm generate ${dir}\` first`
7648
+ );
7649
+ }
7650
+ const selected = manifest.operations[operation];
7651
+ if (!selected) {
7652
+ throw new OrmDefinitionError(
7653
+ `operation "${operation}" is not in ${OPERATIONS_MANIFEST_FILE}; run \`seq-studio orm generate ${dir}\` after editing GraphQL documents`
7654
+ );
7655
+ }
7656
+ const variables = await readExecuteVariables(variablesFile);
7657
+ const response = await apiRequestStrict(
7658
+ "POST",
7659
+ `/_data/v2/${loaded.canonical.namespace}`,
7660
+ { op: selected.hash, variables }
7661
+ );
7662
+ console.log(JSON.stringify(response, null, 2));
7663
+ return 0;
7664
+ }
7572
7665
  async function validateV2Command(dir) {
7573
7666
  const compiled = await compileV2Project(dir);
7574
7667
  printDiagnostics(compiled.ok ? compiled.project.diagnostics : compiled.diagnostics);