@onyx.dev/onyx-database 0.2.0 → 0.3.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/README.md CHANGED
@@ -122,6 +122,9 @@ Generate directly from the API (using the same credential resolver as `init()`):
122
122
  npx onyx-gen --source api --out ./src/onyx/types.ts --name OnyxSchema
123
123
  ```
124
124
 
125
+ With `--source api`, `onyx-gen` calls the Schema API (same as `onyx-schema get`) using the
126
+ standard config chain (env, project file, home profile).
127
+
125
128
  Timestamp attributes are emitted as `Date` fields by default. When saving,
126
129
  `Date` values are automatically serialized to ISO timestamp strings. Pass
127
130
  `--timestamps string` to keep timestamps as ISO strings in generated types.
@@ -132,6 +135,67 @@ Or from a local schema file you export from the console:
132
135
  npx onyx-gen --source file --schema ./onyx.schema.json --out ./src/onyx/types.ts --name OnyxSchema
133
136
  ```
134
137
 
138
+ Run it with no flags to use the defaults: `onyx-gen` reads `./onyx.schema.json` and writes to `./onyx/types.ts`.
139
+
140
+ ### Manage schemas from the CLI
141
+
142
+ Publish or download schema JSON directly via API using the `onyx-schema` helper:
143
+
144
+ ```bash
145
+ # Publish ./onyx.schema.json with publish=true by default
146
+ onyx-schema publish
147
+
148
+ # Overwrite ./onyx.schema.json with the remote schema
149
+ onyx-schema get
150
+
151
+ # Fetch only selected tables (prints to stdout; does not overwrite files)
152
+ onyx-schema get --tables=User,Profile
153
+
154
+ # Example subset output
155
+ onyx-schema get --tables=User,Profile
156
+ # {
157
+ # "tables": [
158
+ # {
159
+ # "name": "User",
160
+ # "attributes": [
161
+ # { "name": "id", "type": "string", "required": true },
162
+ # { "name": "email", "type": "string", "required": true }
163
+ # ]
164
+ # },
165
+ # {
166
+ # "name": "Profile",
167
+ # "attributes": [
168
+ # { "name": "id", "type": "string", "required": true },
169
+ # { "name": "userId", "type": "string", "required": true }
170
+ # ]
171
+ # }
172
+ # ]
173
+ # }
174
+
175
+ # Validate a schema file without publishing
176
+ onyx-schema validate ./onyx.schema.json
177
+ ```
178
+
179
+ When `--tables` is provided, the subset is printed to stdout instead of writing a
180
+ file. Otherwise, the CLI writes to `./onyx.schema.json` by default.
181
+
182
+ In this repo's `examples/` workspace, the following scripts wrap the same commands:
183
+
184
+ ```bash
185
+ npm run schema:get # fetch remote schema into ./onyx.schema.json
186
+ npm run schema:validate # validate the local schema file
187
+ npm run schema:publish # validate then publish the local schema
188
+ ```
189
+
190
+ The CLI reuses the same configuration resolution as `onyx.init()` (env vars,
191
+ project config, and home profile files).
192
+
193
+ You can also emit to multiple paths in one run (comma-separated or by repeating `--out`):
194
+
195
+ ```bash
196
+ onyx-gen --out ./src/onyx/types.ts,./apps/admin/src/onyx/types.ts
197
+ ```
198
+
135
199
  Use in code:
136
200
 
137
201
  ```ts
@@ -398,7 +462,75 @@ const delCount = await db
398
462
 
399
463
  ```
400
464
 
401
- ### 5) Documents API (binary assets)
465
+ ### 5) Schema API
466
+
467
+ ```ts
468
+ import { onyx } from '@onyx.dev/onyx-database';
469
+ const db = onyx.init();
470
+
471
+ // Fetch current schema (optionally filter by tables)
472
+ const schema = await db.getSchema({ tables: ['User', 'Profile'] });
473
+
474
+ // Review history
475
+ const history = await db.getSchemaHistory();
476
+
477
+ // Validate changes without applying
478
+ await db.validateSchema({
479
+ revisionDescription: 'Add profile triggers',
480
+ entities: [
481
+ {
482
+ name: 'Profile',
483
+ identifier: { name: 'id', generator: 'UUID' },
484
+ attributes: [
485
+ { name: 'id', type: 'String', isNullable: false },
486
+ { name: 'userId', type: 'String', isNullable: false },
487
+ ],
488
+ },
489
+ ],
490
+ });
491
+
492
+ // Update and optionally publish
493
+ await db.updateSchema(
494
+ {
495
+ revisionDescription: 'Publish profile changes',
496
+ entities: [
497
+ {
498
+ name: 'Profile',
499
+ identifier: { name: 'id', generator: 'UUID' },
500
+ attributes: [
501
+ { name: 'id', type: 'String', isNullable: false },
502
+ { name: 'userId', type: 'String', isNullable: false },
503
+ ],
504
+ },
505
+ ],
506
+ },
507
+ { publish: true },
508
+ );
509
+ ```
510
+
511
+ ### 6) Secrets API
512
+
513
+ ```ts
514
+ import { onyx } from '@onyx.dev/onyx-database';
515
+ const db = onyx.init();
516
+
517
+ // List secret metadata
518
+ const list = await db.listSecrets();
519
+
520
+ // Read a decrypted secret value
521
+ const secret = await db.getSecret('api-key');
522
+
523
+ // Create or update a secret
524
+ await db.putSecret('api-key', {
525
+ value: 'super-secret',
526
+ purpose: 'Access to external API',
527
+ });
528
+
529
+ // Delete a secret
530
+ await db.deleteSecret('api-key');
531
+ ```
532
+
533
+ ### 7) Documents API (binary assets)
402
534
 
403
535
  ```ts
404
536
  import { onyx, type OnyxDocument } from '@onyx.dev/onyx-database';
@@ -421,7 +553,7 @@ const image = await db.getDocument('logo.png', { width: 128, height: 128 });
421
553
  await db.deleteDocument('logo.png');
422
554
  ```
423
555
 
424
- ### 6) Streaming (live changes)
556
+ ### 8) Streaming (live changes)
425
557
 
426
558
  ```ts
427
559
  import { onyx, eq } from '@onyx.dev/onyx-database';