@sequenceholdings/orm 0.1.0 → 0.1.1

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/index.cjs CHANGED
@@ -24,7 +24,7 @@ var WIRE_TYPES = {
24
24
  };
25
25
  function generateNamespaceTypes(definition) {
26
26
  const lines = [
27
- `// Generated by \`seq-studio orm generate\` from the '${definition.namespace}' definitions \u2014 do not edit.`,
27
+ `// Generated by \`seq-studio orm apply\` from the '${definition.namespace}' definitions \u2014 do not edit.`,
28
28
  "",
29
29
  `export type ${typesInterfaceName(definition.namespace)} = {`
30
30
  ];
@@ -537,6 +537,29 @@ function extractNamedParams(sql2) {
537
537
  function actionStatementSources(executes) {
538
538
  return (Array.isArray(executes) ? executes : [executes]).map((statement) => statement.trim());
539
539
  }
540
+ var WRITE_TARGET_PATTERNS = [
541
+ /^insert\s+into\s+(?:"?[a-z_][a-z0-9_]*"?\.)?"?([a-z_][a-z0-9_]*)"?/i,
542
+ /^update\s+(?:only\s+)?(?:"?[a-z_][a-z0-9_]*"?\.)?"?([a-z_][a-z0-9_]*)"?/i,
543
+ /^delete\s+from\s+(?:only\s+)?(?:"?[a-z_][a-z0-9_]*"?\.)?"?([a-z_][a-z0-9_]*)"?/i
544
+ ];
545
+ function actionWriteTargets(action) {
546
+ const targets = [];
547
+ const seen = /* @__PURE__ */ new Set();
548
+ for (const statement of actionStatementSources(action.executes)) {
549
+ const masked = statement.replace(QUOTED_STRING_PATTERN, "''");
550
+ for (const pattern of WRITE_TARGET_PATTERNS) {
551
+ const match = pattern.exec(masked);
552
+ if (!match) continue;
553
+ const table = match[1].toLowerCase();
554
+ if (!seen.has(table)) {
555
+ seen.add(table);
556
+ targets.push(table);
557
+ }
558
+ break;
559
+ }
560
+ }
561
+ return targets;
562
+ }
540
563
  function executesIssues(executes, declaredParams, hasReturns) {
541
564
  const issues = [];
542
565
  const statements = actionStatementSources(executes);
@@ -2236,6 +2259,7 @@ exports.actionParamOrder = actionParamOrder;
2236
2259
  exports.actionParamSchema = actionParamSchema;
2237
2260
  exports.actionPrepareChecks = actionPrepareChecks;
2238
2261
  exports.actionSchema = actionSchema;
2262
+ exports.actionWriteTargets = actionWriteTargets;
2239
2263
  exports.actionsInterfaceName = actionsInterfaceName;
2240
2264
  exports.applyMigrationHints = applyMigrationHints;
2241
2265
  exports.buildActionParamsSchema = buildActionParamsSchema;