gitsheets 0.22.5 → 1.0.3

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 (72) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/bin/gitsheets +5 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.d.ts.map +1 -0
  6. package/dist/cli/index.js +256 -0
  7. package/dist/cli/index.js.map +1 -0
  8. package/dist/errors.d.ts +72 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +74 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +17 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +12 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/patch.d.ts +2 -0
  17. package/dist/patch.d.ts.map +1 -0
  18. package/dist/patch.js +39 -0
  19. package/dist/patch.js.map +1 -0
  20. package/dist/path-template/index.d.ts +42 -0
  21. package/dist/path-template/index.d.ts.map +1 -0
  22. package/dist/path-template/index.js +288 -0
  23. package/dist/path-template/index.js.map +1 -0
  24. package/dist/push-daemon.d.ts +53 -0
  25. package/dist/push-daemon.d.ts.map +1 -0
  26. package/dist/push-daemon.js +148 -0
  27. package/dist/push-daemon.js.map +1 -0
  28. package/dist/repository.d.ts +67 -0
  29. package/dist/repository.d.ts.map +1 -0
  30. package/dist/repository.js +322 -0
  31. package/dist/repository.js.map +1 -0
  32. package/dist/sheet.d.ts +107 -0
  33. package/dist/sheet.d.ts.map +1 -0
  34. package/dist/sheet.js +605 -0
  35. package/dist/sheet.js.map +1 -0
  36. package/dist/store.d.ts +41 -0
  37. package/dist/store.d.ts.map +1 -0
  38. package/dist/store.js +49 -0
  39. package/dist/store.js.map +1 -0
  40. package/dist/toml.d.ts +11 -0
  41. package/dist/toml.d.ts.map +1 -0
  42. package/dist/toml.js +28 -0
  43. package/dist/toml.js.map +1 -0
  44. package/dist/transaction.d.ts +96 -0
  45. package/dist/transaction.d.ts.map +1 -0
  46. package/dist/transaction.js +227 -0
  47. package/dist/transaction.js.map +1 -0
  48. package/dist/validation.d.ts +37 -0
  49. package/dist/validation.d.ts.map +1 -0
  50. package/dist/validation.js +105 -0
  51. package/dist/validation.js.map +1 -0
  52. package/package.json +41 -35
  53. package/bin/cli.js +0 -61
  54. package/commands/edit.js +0 -90
  55. package/commands/normalize.js +0 -81
  56. package/commands/query.js +0 -206
  57. package/commands/read.js +0 -64
  58. package/commands/singer-target.js +0 -214
  59. package/commands/upsert.js +0 -260
  60. package/lib/GitSheets.js +0 -464
  61. package/lib/Repository.js +0 -88
  62. package/lib/Sheet.js +0 -625
  63. package/lib/errors.js +0 -21
  64. package/lib/hologit.js +0 -1
  65. package/lib/logger.js +0 -18
  66. package/lib/path/BaseComponent.js +0 -24
  67. package/lib/path/ExpressionComponent.js +0 -26
  68. package/lib/path/FieldComponent.js +0 -13
  69. package/lib/path/LiteralComponent.js +0 -12
  70. package/lib/path/Query.js +0 -18
  71. package/lib/path/Template.js +0 -214
  72. package/server.js +0 -120
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # gitsheets
2
+
3
+ A git-backed document store for low-volume, high-touch, human-scale data.
4
+
5
+ > **v1.0 under heavy development.** The library is being rewritten as a
6
+ > TypeScript-only ESM package. The current `develop` (and `1.0-substrate`)
7
+ > branches do not yet expose the documented API. Track progress in the
8
+ > [1.0.0 milestone](https://github.com/JarvusInnovations/gitsheets/milestone/1).
9
+
10
+ ## Spec-driven
11
+
12
+ [`specs/`](specs/) is the source of truth. Start at [`specs/README.md`](specs/README.md).
13
+
14
+ - [`specs/architecture.md`](specs/architecture.md) — stack and packaging
15
+ - [`specs/concepts.md`](specs/concepts.md) — Repository, Sheet, Record, Transaction, Store, Index
16
+ - [`specs/api/`](specs/api/) — per-symbol API contracts
17
+ - [`specs/behaviors/`](specs/behaviors/) — cross-cutting rules
18
+
19
+ ## License
20
+
21
+ [Apache-2.0](LICENSE).
package/bin/gitsheets ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/cli/index.js';
3
+
4
+ const code = await main();
5
+ process.exit(code);
@@ -0,0 +1,2 @@
1
+ export declare function main(args?: string[]): Promise<number>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAsOA,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CAwGlF"}
@@ -0,0 +1,256 @@
1
+ // CLI entry. See specs/api/cli.md.
2
+ // v1.0 substrate ships: upsert, query, read, normalize.
3
+ // infer / migrate-config / edit are tracked as follow-ups against #130, #139.
4
+ import { readFile } from 'node:fs/promises';
5
+ import process from 'node:process';
6
+ import yargs from 'yargs';
7
+ import { hideBin } from 'yargs/helpers';
8
+ import { ConfigError, GitsheetsError, IndexError, NotFoundError, RefError, TransactionError, ValidationError, } from '../errors.js';
9
+ import { openRepo } from '../repository.js';
10
+ // Exit codes per specs/api/cli.md
11
+ function exitCodeForError(err) {
12
+ if (err instanceof ValidationError)
13
+ return 22;
14
+ if (err instanceof ConfigError)
15
+ return 64;
16
+ if (err instanceof RefError)
17
+ return 65;
18
+ if (err instanceof NotFoundError)
19
+ return 66;
20
+ if (err instanceof TransactionError)
21
+ return 69;
22
+ if (err instanceof IndexError)
23
+ return 70;
24
+ if (err instanceof GitsheetsError)
25
+ return 1;
26
+ return 1;
27
+ }
28
+ function reportError(err) {
29
+ const out = process.stderr;
30
+ if (err instanceof GitsheetsError) {
31
+ out.write(`gitsheets: ${err.name}: ${err.message}\n`);
32
+ out.write(` code: ${err.code}\n`);
33
+ if (err instanceof ValidationError && err.issues.length > 0) {
34
+ for (const i of err.issues) {
35
+ out.write(` issue: ${i.path.join('.') || '<root>'}: ${i.message} (${i.source})\n`);
36
+ }
37
+ }
38
+ if (err.cause !== undefined) {
39
+ out.write(` cause: ${err.cause instanceof Error ? err.cause.message : String(err.cause)}\n`);
40
+ }
41
+ return;
42
+ }
43
+ if (err instanceof Error) {
44
+ out.write(`gitsheets: ${err.name}: ${err.message}\n`);
45
+ return;
46
+ }
47
+ out.write(`gitsheets: ${String(err)}\n`);
48
+ }
49
+ async function readInput(input) {
50
+ if (input === undefined || input === '-') {
51
+ const chunks = [];
52
+ for await (const chunk of process.stdin) {
53
+ chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
54
+ }
55
+ return Buffer.concat(chunks).toString('utf8');
56
+ }
57
+ // Treat anything starting with `{` or `[` as inline JSON, otherwise a path.
58
+ const trimmed = input.trimStart();
59
+ if (trimmed.startsWith('{') || trimmed.startsWith('['))
60
+ return input;
61
+ return readFile(input, 'utf8');
62
+ }
63
+ function parseJsonRecords(text) {
64
+ const trimmed = text.trim();
65
+ if (!trimmed)
66
+ return [];
67
+ // JSON array → many records; JSON object → single record; one-record-per-line JSONL → many.
68
+ if (trimmed.startsWith('[')) {
69
+ const arr = JSON.parse(trimmed);
70
+ if (!Array.isArray(arr))
71
+ throw new Error('expected JSON array of records');
72
+ return arr;
73
+ }
74
+ if (trimmed.startsWith('{')) {
75
+ return [JSON.parse(trimmed)];
76
+ }
77
+ // JSONL fallback
78
+ return trimmed
79
+ .split('\n')
80
+ .filter((line) => line.trim().length > 0)
81
+ .map((line) => JSON.parse(line));
82
+ }
83
+ async function loadRepoAndSheet(argv) {
84
+ const repo = await openRepo(argv.gitDir ? { gitDir: argv.gitDir } : {});
85
+ const sheet = await repo.openSheet(argv.sheet, argv.root ? { root: argv.root } : {});
86
+ return { repo, sheet };
87
+ }
88
+ function buildTxOpts(argv, defaultMessage) {
89
+ const opts = { message: argv.message ?? defaultMessage };
90
+ if (argv.authorName && argv.authorEmail) {
91
+ opts.author = { name: argv.authorName, email: argv.authorEmail };
92
+ }
93
+ if (argv.trailer && Object.keys(argv.trailer).length > 0) {
94
+ opts.trailers = argv.trailer;
95
+ }
96
+ if (argv.ref)
97
+ opts.parent = argv.ref;
98
+ if (argv.commitTo)
99
+ opts.branch = argv.commitTo;
100
+ return opts;
101
+ }
102
+ // --- Commands ---
103
+ async function runUpsert(argv) {
104
+ const { repo, sheet } = await loadRepoAndSheet(argv);
105
+ void sheet; // loadRepoAndSheet validates the config exists
106
+ const text = await readInput(argv.input);
107
+ const records = parseJsonRecords(text);
108
+ if (records.length === 0)
109
+ return;
110
+ const txOpts = buildTxOpts(argv, `${argv.sheet} upsert (${records.length})`);
111
+ await repo.transact(txOpts, async (tx) => {
112
+ const target = tx.sheet(argv.sheet);
113
+ for (const record of records) {
114
+ const result = await target.upsert(record);
115
+ process.stdout.write(`${result.blob.hash} ${result.path}\n`);
116
+ }
117
+ });
118
+ }
119
+ async function runQuery(argv) {
120
+ const { sheet } = await loadRepoAndSheet(argv);
121
+ const filter = argv.filter ?? {};
122
+ let yielded = 0;
123
+ for await (const record of sheet.query(filter)) {
124
+ const out = argv.fields
125
+ ? Object.fromEntries(argv.fields.map((f) => [f, record[f]]))
126
+ : record;
127
+ // Strip well-known symbols before serializing
128
+ process.stdout.write(`${JSON.stringify(out)}\n`);
129
+ yielded++;
130
+ if (argv.limit !== undefined && yielded >= argv.limit)
131
+ break;
132
+ }
133
+ }
134
+ async function runRead(argv) {
135
+ const { sheet } = await loadRepoAndSheet(argv);
136
+ // The path is treated as the record's full slug-rendered key plus optional
137
+ // .toml extension. For the simple `${{ slug }}` case this is just the slug.
138
+ const target = argv.path.endsWith('.toml') ? argv.path.slice(0, -5) : argv.path;
139
+ // Query by RECORD_PATH_KEY isn't supported through `query()` directly; iterate
140
+ // and match. For typical sheets this is small enough.
141
+ let found;
142
+ for await (const record of sheet.query()) {
143
+ const pathSym = record[Symbol.for('gitsheets-path')];
144
+ if (pathSym === target) {
145
+ found = record;
146
+ break;
147
+ }
148
+ }
149
+ if (!found) {
150
+ throw new NotFoundError('record_not_found', `${argv.sheet}: no record at ${target}`);
151
+ }
152
+ process.stdout.write(`${JSON.stringify(found, null, 2)}\n`);
153
+ }
154
+ async function runNormalize(argv) {
155
+ const { repo, sheet } = await loadRepoAndSheet(argv);
156
+ const records = [];
157
+ for await (const r of sheet.query()) {
158
+ records.push(r);
159
+ }
160
+ if (records.length === 0)
161
+ return;
162
+ const txOpts = buildTxOpts(argv, `${argv.sheet} normalize`);
163
+ await repo.transact(txOpts, async (tx) => {
164
+ const target = tx.sheet(argv.sheet);
165
+ for (const r of records) {
166
+ const result = await target.upsert(r);
167
+ process.stdout.write(`${result.blob.hash} ${result.path}\n`);
168
+ }
169
+ });
170
+ }
171
+ // --- Entry ---
172
+ export async function main(args = hideBin(process.argv)) {
173
+ const parser = yargs(args)
174
+ .scriptName('gitsheets')
175
+ .usage('Usage: $0 <command> [options]')
176
+ .strict()
177
+ .demandCommand(1, 'Specify a command')
178
+ .option('git-dir', {
179
+ type: 'string',
180
+ describe: 'Path to a .git directory; default: $GIT_DIR or discovered from cwd',
181
+ default: process.env['GIT_DIR'],
182
+ })
183
+ .option('root', { type: 'string', describe: 'Sub-directory under the data tree; default "/"' })
184
+ .option('ref', { type: 'string', describe: "Parent ref/commit; default HEAD's branch" })
185
+ .option('commit-to', { type: 'string', describe: 'Branch to update on commit' })
186
+ .option('message', { type: 'string', describe: 'Commit message (mutating commands)' })
187
+ .option('author-name', { type: 'string', describe: 'Commit author name' })
188
+ .option('author-email', { type: 'string', describe: 'Commit author email' })
189
+ .option('trailer', {
190
+ type: 'string',
191
+ array: true,
192
+ describe: 'Commit trailers in Key=Value form (repeatable)',
193
+ coerce: (raw) => {
194
+ const items = Array.isArray(raw) ? raw : [raw];
195
+ const out = {};
196
+ for (const item of items) {
197
+ const eq = item.indexOf('=');
198
+ if (eq === -1)
199
+ throw new Error(`--trailer expects Key=Value, got ${item}`);
200
+ out[item.slice(0, eq)] = item.slice(eq + 1);
201
+ }
202
+ return out;
203
+ },
204
+ })
205
+ .env('GITSHEETS')
206
+ .command('upsert <sheet> [input]', 'Insert or update one or more records', (y) => y
207
+ .positional('sheet', { type: 'string', demandOption: true })
208
+ .positional('input', {
209
+ type: 'string',
210
+ describe: "Inline JSON, a file path, or '-' for stdin",
211
+ }), runUpsert)
212
+ .command('query <sheet>', 'Read records as newline-delimited JSON', (y) => y
213
+ .positional('sheet', { type: 'string', demandOption: true })
214
+ .option('filter', {
215
+ type: 'string',
216
+ array: true,
217
+ describe: 'Equality filter as field=value (repeatable)',
218
+ coerce: (raw) => {
219
+ const items = Array.isArray(raw) ? raw : [raw];
220
+ const out = {};
221
+ for (const item of items) {
222
+ const eq = item.indexOf('=');
223
+ if (eq === -1)
224
+ throw new Error(`--filter expects field=value, got ${item}`);
225
+ out[item.slice(0, eq)] = item.slice(eq + 1);
226
+ }
227
+ return out;
228
+ },
229
+ })
230
+ .option('fields', { type: 'string', array: true })
231
+ .option('limit', { type: 'number' }), runQuery)
232
+ .command('read <sheet> <path>', 'Read a single record by its rendered path', (y) => y
233
+ .positional('sheet', { type: 'string', demandOption: true })
234
+ .positional('path', { type: 'string', demandOption: true }), runRead)
235
+ .command('normalize <sheet>', 'Re-write every record through the canonical-normalization pipeline', (y) => y.positional('sheet', { type: 'string', demandOption: true }), runNormalize)
236
+ .fail((msg, err) => {
237
+ if (err) {
238
+ reportError(err);
239
+ process.exit(exitCodeForError(err));
240
+ }
241
+ process.stderr.write(`gitsheets: ${msg}\n`);
242
+ process.exit(2);
243
+ })
244
+ .help()
245
+ .alias('h', 'help')
246
+ .version();
247
+ try {
248
+ await parser.parseAsync();
249
+ return 0;
250
+ }
251
+ catch (err) {
252
+ reportError(err);
253
+ return exitCodeForError(err);
254
+ }
255
+ }
256
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,mCA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UAAU,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
@@ -0,0 +1,72 @@
1
+ export interface ValidationIssue {
2
+ readonly path: string[];
3
+ readonly message: string;
4
+ readonly source: 'json-schema' | 'standard-schema';
5
+ readonly schemaPath?: string;
6
+ readonly code?: string;
7
+ }
8
+ declare const STATUS_BY_CODE: {
9
+ readonly config_missing: 500;
10
+ readonly config_invalid: 500;
11
+ readonly validation_failed: 422;
12
+ readonly transaction_in_progress: 409;
13
+ readonly transaction_required: 409;
14
+ readonly parent_moved: 409;
15
+ readonly commit_failed: 500;
16
+ readonly index_unique_conflict: 409;
17
+ readonly index_not_defined: 500;
18
+ readonly push_daemon_running: 409;
19
+ readonly transaction_closed: 409;
20
+ readonly ref_not_found: 404;
21
+ readonly not_an_ancestor: 409;
22
+ readonly path_render_failed: 422;
23
+ readonly path_invalid_chars: 422;
24
+ readonly record_not_found: 404;
25
+ };
26
+ export type GitsheetsErrorCode = keyof typeof STATUS_BY_CODE;
27
+ interface GitsheetsErrorOptions {
28
+ readonly cause?: unknown;
29
+ }
30
+ export declare class GitsheetsError extends Error {
31
+ readonly code: GitsheetsErrorCode;
32
+ readonly status: number;
33
+ constructor(code: GitsheetsErrorCode, message: string, options?: GitsheetsErrorOptions);
34
+ }
35
+ export type ConfigErrorCode = 'config_missing' | 'config_invalid';
36
+ export declare class ConfigError extends GitsheetsError {
37
+ constructor(code: ConfigErrorCode, message: string, options?: GitsheetsErrorOptions);
38
+ }
39
+ export type ValidationErrorCode = 'validation_failed';
40
+ interface ValidationErrorOptions extends GitsheetsErrorOptions {
41
+ readonly issues: readonly ValidationIssue[];
42
+ }
43
+ export declare class ValidationError extends GitsheetsError {
44
+ readonly issues: readonly ValidationIssue[];
45
+ constructor(code: ValidationErrorCode, message: string, options: ValidationErrorOptions);
46
+ }
47
+ export type TransactionErrorCode = 'transaction_in_progress' | 'transaction_required' | 'parent_moved' | 'commit_failed' | 'push_daemon_running' | 'transaction_closed';
48
+ export declare class TransactionError extends GitsheetsError {
49
+ constructor(code: TransactionErrorCode, message: string, options?: GitsheetsErrorOptions);
50
+ }
51
+ export type IndexErrorCode = 'index_unique_conflict' | 'index_not_defined';
52
+ interface IndexErrorOptions extends GitsheetsErrorOptions {
53
+ readonly conflictingPaths?: readonly string[];
54
+ }
55
+ export declare class IndexError extends GitsheetsError {
56
+ readonly conflictingPaths?: readonly string[];
57
+ constructor(code: IndexErrorCode, message: string, options?: IndexErrorOptions);
58
+ }
59
+ export type RefErrorCode = 'ref_not_found' | 'not_an_ancestor';
60
+ export declare class RefError extends GitsheetsError {
61
+ constructor(code: RefErrorCode, message: string, options?: GitsheetsErrorOptions);
62
+ }
63
+ export type PathTemplateErrorCode = 'path_render_failed' | 'path_invalid_chars';
64
+ export declare class PathTemplateError extends GitsheetsError {
65
+ constructor(code: PathTemplateErrorCode, message: string, options?: GitsheetsErrorOptions);
66
+ }
67
+ export type NotFoundErrorCode = 'record_not_found';
68
+ export declare class NotFoundError extends GitsheetsError {
69
+ constructor(code: NotFoundErrorCode, message: string, options?: GitsheetsErrorOptions);
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,iBAAiB,CAAC;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,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AqB;IACvD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/C;AAED,qBAAa,UAAW,SAAQ,cAAc;IAC5C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;gBAElC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAM/E;AAED,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAE/D,qBAAa,QAAS,SAAQ,cAAc;gBAC9B,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;CAGjF;AAED,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAEhF,qBAAa,iBAAkB,SAAQ,cAAc;gBACvC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;CAG1F;AAED,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEnD,qBAAa,aAAc,SAAQ,cAAc;gBACnC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;CAGtF"}
package/dist/errors.js ADDED
@@ -0,0 +1,74 @@
1
+ // Typed exception hierarchy with stable codes.
2
+ // See specs/api/errors.md for the contract.
3
+ const STATUS_BY_CODE = {
4
+ config_missing: 500,
5
+ config_invalid: 500,
6
+ validation_failed: 422,
7
+ transaction_in_progress: 409,
8
+ transaction_required: 409,
9
+ parent_moved: 409,
10
+ commit_failed: 500,
11
+ index_unique_conflict: 409,
12
+ index_not_defined: 500,
13
+ push_daemon_running: 409,
14
+ transaction_closed: 409,
15
+ ref_not_found: 404,
16
+ not_an_ancestor: 409,
17
+ path_render_failed: 422,
18
+ path_invalid_chars: 422,
19
+ record_not_found: 404,
20
+ };
21
+ export class GitsheetsError extends Error {
22
+ code;
23
+ status;
24
+ constructor(code, message, options) {
25
+ // Avoid passing { cause: undefined } when no cause was provided — keeps
26
+ // err.cause unset for clean inspection, and satisfies exactOptionalPropertyTypes.
27
+ super(message, options?.cause === undefined ? undefined : { cause: options.cause });
28
+ this.code = code;
29
+ this.status = STATUS_BY_CODE[code];
30
+ this.name = new.target.name;
31
+ }
32
+ }
33
+ export class ConfigError extends GitsheetsError {
34
+ constructor(code, message, options) {
35
+ super(code, message, options);
36
+ }
37
+ }
38
+ export class ValidationError extends GitsheetsError {
39
+ issues;
40
+ constructor(code, message, options) {
41
+ super(code, message, options.cause === undefined ? undefined : { cause: options.cause });
42
+ this.issues = options.issues;
43
+ }
44
+ }
45
+ export class TransactionError extends GitsheetsError {
46
+ constructor(code, message, options) {
47
+ super(code, message, options);
48
+ }
49
+ }
50
+ export class IndexError extends GitsheetsError {
51
+ conflictingPaths;
52
+ constructor(code, message, options) {
53
+ super(code, message, options?.cause === undefined ? undefined : { cause: options.cause });
54
+ if (options?.conflictingPaths !== undefined) {
55
+ this.conflictingPaths = options.conflictingPaths;
56
+ }
57
+ }
58
+ }
59
+ export class RefError extends GitsheetsError {
60
+ constructor(code, message, options) {
61
+ super(code, message, options);
62
+ }
63
+ }
64
+ export class PathTemplateError extends GitsheetsError {
65
+ constructor(code, message, options) {
66
+ super(code, message, options);
67
+ }
68
+ }
69
+ export class NotFoundError extends GitsheetsError {
70
+ constructor(code, message, options) {
71
+ super(code, message, options);
72
+ }
73
+ }
74
+ //# sourceMappingURL=errors.js.map