@pgpmjs/import 0.11.10 → 0.11.11

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/esm/import.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { pathFor } from '@pgpmjs/naming-spec';
2
- import { classifyStatements, loadModule, regenerateScripts, restructureExportRows } from '@pgpmjs/transform';
2
+ import { classifyStatements, loadModule, regenerateScripts, restructureExportRows, sliceStatementBytes, sqlSourceBytes } from '@pgpmjs/transform';
3
3
  import { copyBlockToInsert, copyTargetOf } from './dump-source';
4
4
  export const MISC_CHANGE_PATH = 'misc/statements';
5
5
  const stringVal = (node) => typeof node?.String?.sval === 'string' ? node.String.sval : null;
@@ -120,7 +120,8 @@ const reorderChangeStatements = (content) => {
120
120
  const ordered = [...creates, ...riders];
121
121
  if (ordered.every((f, i) => f === facts[i]))
122
122
  return content;
123
- return ordered.map(f => statementText(content, f)).join('\n\n') + '\n';
123
+ const contentBytes = sqlSourceBytes(content);
124
+ return ordered.map(f => statementText(contentBytes, f)).join('\n\n') + '\n';
124
125
  };
125
126
  /**
126
127
  * Order a revert's statements drops-last (stable), mirroring the deploy
@@ -136,22 +137,23 @@ const reorderRevertStatements = (content) => {
136
137
  const ordered = [...facts.filter(f => !isDrop(f)), ...facts.filter(isDrop)];
137
138
  if (ordered.every((f, i) => f === facts[i]))
138
139
  return content;
140
+ const contentBytes = sqlSourceBytes(content);
139
141
  let leftover = content;
140
142
  for (const f of facts) {
141
- leftover = leftover.replace(content.slice(f.span.start, f.span.start + f.span.len), '');
143
+ leftover = leftover.replace(sliceStatementBytes(contentBytes, f.span.start, f.span.len), '');
142
144
  }
143
145
  const notes = leftover
144
146
  .split('\n')
145
147
  .map(line => line.trim())
146
148
  .filter(line => line.startsWith('--'));
147
- return [...ordered.map(f => statementText(content, f)), ...notes].join('\n\n') + '\n';
149
+ return [...ordered.map(f => statementText(contentBytes, f)), ...notes].join('\n\n') + '\n';
148
150
  };
149
151
  const SET_CONFIG = /^SELECT\s+(pg_catalog\.)?set_config\s*\(/i;
150
152
  const SETVAL = /^SELECT\s+(pg_catalog\.)?setval\s*\(\s*'([^']+)'/i;
151
153
  const isPreamble = (facts, text) => facts.nodeTag === 'VariableSetStmt' ||
152
154
  (facts.nodeTag === 'SelectStmt' && SET_CONFIG.test(text));
153
- const statementText = (sql, facts) => {
154
- const text = sql.slice(facts.span.start, facts.span.start + facts.span.len).trim();
155
+ const statementText = (sqlBytes, facts) => {
156
+ const text = sliceStatementBytes(sqlBytes, facts.span.start, facts.span.len).trim();
155
157
  return text.endsWith(';') ? text : `${text};`;
156
158
  };
157
159
  const seedVerify = (schema, name) => {
@@ -277,6 +279,7 @@ export const importDumpRows = async (source, options = {}) => {
277
279
  let skippedPreamble = source.metaCommands.length;
278
280
  let skippedData = 0;
279
281
  const facts = classifyStatements(source.sql);
282
+ const sourceBytes = sqlSourceBytes(source.sql);
280
283
  // Main statements (those creating/targeting an object) in dump order, with
281
284
  // per-statement rider buckets so riders re-attach right after their host.
282
285
  const mainTexts = [];
@@ -285,7 +288,7 @@ export const importDumpRows = async (source, options = {}) => {
285
288
  const pendingRiders = [];
286
289
  const ownedSequences = [];
287
290
  for (const f of facts) {
288
- const text = statementText(source.sql, f);
291
+ const text = statementText(sourceBytes, f);
289
292
  if (isPreamble(f, text)) {
290
293
  skippedPreamble++;
291
294
  continue;
package/import.js CHANGED
@@ -123,7 +123,8 @@ const reorderChangeStatements = (content) => {
123
123
  const ordered = [...creates, ...riders];
124
124
  if (ordered.every((f, i) => f === facts[i]))
125
125
  return content;
126
- return ordered.map(f => statementText(content, f)).join('\n\n') + '\n';
126
+ const contentBytes = (0, transform_1.sqlSourceBytes)(content);
127
+ return ordered.map(f => statementText(contentBytes, f)).join('\n\n') + '\n';
127
128
  };
128
129
  /**
129
130
  * Order a revert's statements drops-last (stable), mirroring the deploy
@@ -139,22 +140,23 @@ const reorderRevertStatements = (content) => {
139
140
  const ordered = [...facts.filter(f => !isDrop(f)), ...facts.filter(isDrop)];
140
141
  if (ordered.every((f, i) => f === facts[i]))
141
142
  return content;
143
+ const contentBytes = (0, transform_1.sqlSourceBytes)(content);
142
144
  let leftover = content;
143
145
  for (const f of facts) {
144
- leftover = leftover.replace(content.slice(f.span.start, f.span.start + f.span.len), '');
146
+ leftover = leftover.replace((0, transform_1.sliceStatementBytes)(contentBytes, f.span.start, f.span.len), '');
145
147
  }
146
148
  const notes = leftover
147
149
  .split('\n')
148
150
  .map(line => line.trim())
149
151
  .filter(line => line.startsWith('--'));
150
- return [...ordered.map(f => statementText(content, f)), ...notes].join('\n\n') + '\n';
152
+ return [...ordered.map(f => statementText(contentBytes, f)), ...notes].join('\n\n') + '\n';
151
153
  };
152
154
  const SET_CONFIG = /^SELECT\s+(pg_catalog\.)?set_config\s*\(/i;
153
155
  const SETVAL = /^SELECT\s+(pg_catalog\.)?setval\s*\(\s*'([^']+)'/i;
154
156
  const isPreamble = (facts, text) => facts.nodeTag === 'VariableSetStmt' ||
155
157
  (facts.nodeTag === 'SelectStmt' && SET_CONFIG.test(text));
156
- const statementText = (sql, facts) => {
157
- const text = sql.slice(facts.span.start, facts.span.start + facts.span.len).trim();
158
+ const statementText = (sqlBytes, facts) => {
159
+ const text = (0, transform_1.sliceStatementBytes)(sqlBytes, facts.span.start, facts.span.len).trim();
158
160
  return text.endsWith(';') ? text : `${text};`;
159
161
  };
160
162
  const seedVerify = (schema, name) => {
@@ -281,6 +283,7 @@ const importDumpRows = async (source, options = {}) => {
281
283
  let skippedPreamble = source.metaCommands.length;
282
284
  let skippedData = 0;
283
285
  const facts = (0, transform_1.classifyStatements)(source.sql);
286
+ const sourceBytes = (0, transform_1.sqlSourceBytes)(source.sql);
284
287
  // Main statements (those creating/targeting an object) in dump order, with
285
288
  // per-statement rider buckets so riders re-attach right after their host.
286
289
  const mainTexts = [];
@@ -289,7 +292,7 @@ const importDumpRows = async (source, options = {}) => {
289
292
  const pendingRiders = [];
290
293
  const ownedSequences = [];
291
294
  for (const f of facts) {
292
- const text = statementText(source.sql, f);
295
+ const text = statementText(sourceBytes, f);
293
296
  if (isPreamble(f, text)) {
294
297
  skippedPreamble++;
295
298
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/import",
3
- "version": "0.11.10",
3
+ "version": "0.11.11",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "pgpm import — pgpm-itize arbitrary SQL dumps (pg_dump output, raw .sql) through the dials pipeline",
6
6
  "main": "index.js",
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@pgpmjs/ast": "^0.16.4",
37
- "@pgpmjs/naming-spec": "^0.6.3",
38
- "@pgpmjs/transform": "^0.32.10"
37
+ "@pgpmjs/transform": "^0.32.11",
38
+ "@pgpmjs/naming-spec": "^0.6.3"
39
39
  },
40
40
  "scripts": {
41
41
  "clean": "makage clean",