@pgpmjs/ast 0.1.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.
Files changed (81) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +99 -0
  3. package/esm/files/extension/index.js +3 -0
  4. package/esm/files/extension/reader.js +79 -0
  5. package/esm/files/extension/writer.js +99 -0
  6. package/esm/files/index.js +6 -0
  7. package/esm/files/plan/generator.js +82 -0
  8. package/esm/files/plan/index.js +5 -0
  9. package/esm/files/plan/parser.js +297 -0
  10. package/esm/files/plan/validators.js +181 -0
  11. package/esm/files/plan/writer.js +142 -0
  12. package/esm/files/sql/header.js +259 -0
  13. package/esm/files/sql/index.js +2 -0
  14. package/esm/files/sql/writer.js +107 -0
  15. package/esm/files/sql-scripts/index.js +2 -0
  16. package/esm/files/sql-scripts/reader.js +19 -0
  17. package/esm/files/types/index.js +1 -0
  18. package/esm/files/types/package.js +1 -0
  19. package/esm/hash.js +9 -0
  20. package/esm/index.js +18 -0
  21. package/esm/module/index.js +12 -0
  22. package/esm/module/parse.js +27 -0
  23. package/esm/module/reader.js +64 -0
  24. package/esm/module/roundtrip.js +65 -0
  25. package/esm/module/types.js +1 -0
  26. package/esm/module/writer.js +45 -0
  27. package/esm/plan-rename.js +28 -0
  28. package/esm/utils/author.js +11 -0
  29. package/files/extension/index.d.ts +2 -0
  30. package/files/extension/index.js +19 -0
  31. package/files/extension/reader.d.ts +24 -0
  32. package/files/extension/reader.js +86 -0
  33. package/files/extension/writer.d.ts +48 -0
  34. package/files/extension/writer.js +107 -0
  35. package/files/index.d.ts +5 -0
  36. package/files/index.js +22 -0
  37. package/files/plan/generator.d.ts +23 -0
  38. package/files/plan/generator.js +90 -0
  39. package/files/plan/index.d.ts +4 -0
  40. package/files/plan/index.js +21 -0
  41. package/files/plan/parser.d.ts +28 -0
  42. package/files/plan/parser.js +304 -0
  43. package/files/plan/validators.d.ts +52 -0
  44. package/files/plan/validators.js +187 -0
  45. package/files/plan/writer.d.ts +27 -0
  46. package/files/plan/writer.js +152 -0
  47. package/files/sql/header.d.ts +114 -0
  48. package/files/sql/header.js +266 -0
  49. package/files/sql/index.d.ts +2 -0
  50. package/files/sql/index.js +18 -0
  51. package/files/sql/writer.d.ts +12 -0
  52. package/files/sql/writer.js +114 -0
  53. package/files/sql-scripts/index.d.ts +1 -0
  54. package/files/sql-scripts/index.js +18 -0
  55. package/files/sql-scripts/reader.d.ts +8 -0
  56. package/files/sql-scripts/reader.js +23 -0
  57. package/files/types/index.d.ts +46 -0
  58. package/files/types/index.js +17 -0
  59. package/files/types/package.d.ts +20 -0
  60. package/files/types/package.js +2 -0
  61. package/hash.d.ts +6 -0
  62. package/hash.js +12 -0
  63. package/index.d.ts +19 -0
  64. package/index.js +36 -0
  65. package/module/index.d.ts +12 -0
  66. package/module/index.js +28 -0
  67. package/module/parse.d.ts +23 -0
  68. package/module/parse.js +31 -0
  69. package/module/reader.d.ts +13 -0
  70. package/module/reader.js +67 -0
  71. package/module/roundtrip.d.ts +22 -0
  72. package/module/roundtrip.js +68 -0
  73. package/module/types.d.ts +72 -0
  74. package/module/types.js +2 -0
  75. package/module/writer.d.ts +30 -0
  76. package/module/writer.js +50 -0
  77. package/package.json +48 -0
  78. package/plan-rename.d.ts +8 -0
  79. package/plan-rename.js +31 -0
  80. package/utils/author.d.ts +5 -0
  81. package/utils/author.js +14 -0
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@pgpmjs/ast",
3
+ "version": "0.1.0",
4
+ "author": "Constructive <developers@constructive.io>",
5
+ "description": "PGPM module AST — plan/control/SQL-header parsers and the lossless module read/write layer",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/constructive-io/constructive",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/constructive-io/constructive"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/constructive-io/constructive/issues"
21
+ },
22
+ "scripts": {
23
+ "clean": "makage clean",
24
+ "prepack": "npm run build",
25
+ "build": "makage build",
26
+ "build:dev": "makage build --dev",
27
+ "lint": "eslint . --fix",
28
+ "test": "jest --passWithNoTests",
29
+ "test:watch": "jest --watch"
30
+ },
31
+ "keywords": [
32
+ "ast",
33
+ "plan",
34
+ "typescript",
35
+ "pgpm",
36
+ "pgpmjs",
37
+ "postgresql",
38
+ "migrations"
39
+ ],
40
+ "devDependencies": {
41
+ "makage": "^0.3.0"
42
+ },
43
+ "dependencies": {
44
+ "@pgpmjs/env": "^2.28.2",
45
+ "@pgpmjs/types": "^2.35.1"
46
+ },
47
+ "gitHead": "15a831fa029544068ee64e3386e4b08715d2b86d"
48
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Rewrite change names in a pgpm.plan's content according to a rename map.
3
+ * Textual and format-preserving: only the change-name token at the start of a
4
+ * change line, plain (same-package) dependency refs inside `[...]`, and tag
5
+ * lines' change field are rewritten; timestamps, planners, comments,
6
+ * cross-package refs, and tag refs are untouched.
7
+ */
8
+ export declare function renameInPlanContent(content: string, renames: Map<string, string>): string;
package/plan-rename.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameInPlanContent = renameInPlanContent;
4
+ function escapeRe(str) {
5
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
6
+ }
7
+ /**
8
+ * Rewrite change names in a pgpm.plan's content according to a rename map.
9
+ * Textual and format-preserving: only the change-name token at the start of a
10
+ * change line, plain (same-package) dependency refs inside `[...]`, and tag
11
+ * lines' change field are rewritten; timestamps, planners, comments,
12
+ * cross-package refs, and tag refs are untouched.
13
+ */
14
+ function renameInPlanContent(content, renames) {
15
+ const froms = Array.from(renames.keys()).sort((a, b) => b.length - a.length);
16
+ return content
17
+ .split('\n')
18
+ .map(line => {
19
+ const trimmed = line.trim();
20
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('%'))
21
+ return line;
22
+ let result = line;
23
+ for (const from of froms) {
24
+ const to = renames.get(from);
25
+ const re = new RegExp(`(^|[\\s\\[])${escapeRe(from)}(?=$|[\\s\\]@])`, 'g');
26
+ result = result.replace(re, `$1${to}`);
27
+ }
28
+ return result;
29
+ })
30
+ .join('\n');
31
+ }
@@ -0,0 +1,5 @@
1
+ export interface ParsedAuthor {
2
+ fullName: string;
3
+ email?: string;
4
+ }
5
+ export declare function parseAuthor(author: string): ParsedAuthor;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAuthor = parseAuthor;
4
+ function parseAuthor(author) {
5
+ const trimmed = (author || '').trim();
6
+ const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/);
7
+ if (match) {
8
+ return {
9
+ fullName: match[1].trim(),
10
+ email: match[2].trim()
11
+ };
12
+ }
13
+ return { fullName: trimmed };
14
+ }