@stacksjs/defaults 0.75.561 → 0.75.562

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.
@@ -66,7 +66,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
66
66
  | `@stacksjs/newsletter` | [`stacks-newsletter`](../stacks-newsletter/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/index.ts) | 10 |
67
67
  | `@stacksjs/notifications` | [`stacks-notifications`](../stacks-notifications/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/notifications/src/index.ts) | 18 |
68
68
  | `@stacksjs/objects` | [`stacks-objects`](../stacks-objects/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/objects/src/index.ts) | 10 |
69
- | `@stacksjs/orm` | [`stacks-orm`](../stacks-orm/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts) | 77 |
69
+ | `@stacksjs/orm` | [`stacks-orm`](../stacks-orm/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts) | 78 |
70
70
  | `@stacksjs/pagination` | [`stacks-pagination`](../stacks-pagination/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/pagination/src/index.ts) | 1 |
71
71
  | `@stacksjs/path` | [`stacks-path`](../stacks-path/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/path/src/index.ts) | 13 |
72
72
  | `@stacksjs/payments` | [`stacks-payments`](../stacks-payments/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/index.ts) | 39 |
@@ -648,11 +648,11 @@ Evidence directory: [10 retained tests](https://github.com/stacksjs/stacks/blob/
648
648
 
649
649
  Guidance: [`stacks-orm`](../stacks-orm/SKILL.md). Source: [storage/framework/core/orm/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts).
650
650
 
651
- Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseActivation`, `LicenseKey`, `LicenseSeat`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
651
+ Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseActivation`, `LicenseKey`, `LicenseSeat`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `decryptValueInPlace`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
652
652
 
653
653
  Local source modules: [src/auto-crud.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/auto-crud.ts), [src/batch-loader.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/batch-loader.ts), [src/db.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/db.ts), [src/define-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/define-model.ts), [src/extend-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/extend-model.ts), [src/gdpr/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/gdpr/index.ts), [src/generate-database-schema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/generate-database-schema.ts), [src/locked-row.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/locked-row.ts), [src/messaging.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/messaging.ts), [src/model-types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/model-types.ts), [src/ownership.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/ownership.ts), [src/paginator-request.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/paginator-request.ts), [src/row-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/row-token.ts), [src/subquery.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/subquery.ts), [src/traits/audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/audit.ts), [src/traits/billable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/billable.ts), [src/traits/categorizable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/categorizable.ts), [src/traits/commentable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/commentable.ts), [src/traits/likeable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/likeable.ts), [src/traits/taggable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/taggable.ts), [src/transaction.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/transaction.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/types.ts), [src/utils/encrypted.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/encrypted.ts), [src/utils/prunable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/prunable.ts).
654
654
 
655
- Evidence directory: [77 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
655
+ Evidence directory: [78 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
656
656
 
657
657
  ### @stacksjs/pagination
658
658
 
@@ -25,8 +25,8 @@ import type { ModelRow, ModelCreateData } from '@stacksjs/orm'
25
25
  type WorkItemRow = ModelRow<typeof WorkItem>
26
26
  type NewWorkItem = ModelCreateData<typeof WorkItem>
27
27
 
28
- const item = await WorkItem.find(id)
29
- const open = await WorkItem.where('done', false).orderBy('id', 'desc').get()
28
+ const item = WorkItem.find(id)
29
+ const open = WorkItem.where('done', false).orderBy('id', 'desc').get()
30
30
  ```
31
31
 
32
32
  `find` can return no row; `findOrFail` throws `ModelNotFoundError`. Do not invent
@@ -34,6 +34,44 @@ const open = await WorkItem.where('done', false).orderBy('id', 'desc').get()
34
34
  load lazily; server boot waits for model initialization. A feature-disabled
35
35
  model is not made usable merely by an ambient declaration.
36
36
 
37
+ ## Reads answer in place, writes are promises
38
+
39
+ A model read returns its value where it is written, on SQLite, MySQL and
40
+ Postgres:
41
+
42
+ ```ts
43
+ const user = User.where('email', 'like', '%@example.com').orderByDesc('created_at').first()
44
+ user?.email // the row is already here
45
+
46
+ const total = User.count()
47
+ if (User.where('email', email).exists()) return response.badRequest('Taken')
48
+ for (const post of Post.where('published', true).get()) titles.push(post.title)
49
+ ```
50
+
51
+ - **Which calls:** every read. `find`, `findOrFail`, `findMany`, `first`,
52
+ `firstOrFail`, `last`, `all`, `get`, `count`, `exists`, `pluck`, `sum`,
53
+ `avg`, `min`, `max`, `paginate`, `simplePaginate`, `cursorPaginate`, eager
54
+ loading through `with()`, and reads of encrypted attributes.
55
+ - **`await` still works.** `await` on a value is that value, so existing code
56
+ and code written by habit run unchanged. The types say the same: a read is
57
+ typed as the row, not as a promise of it.
58
+ - **A failure is thrown where the call stands.** `findOrFail` on a missing
59
+ row throws; wrap it in `try`/`catch`. `.catch()` and `.then()` do not exist
60
+ on a row. In a test, `expect(() => User.findOrFail(0)).toThrow()`, not
61
+ `await expect(...).rejects`.
62
+ - **A write is a promise, on every model.** `create`, `createMany`,
63
+ `firstOrCreate`, `updateOrCreate`, `update`, `save`, `delete`, `forceDelete`
64
+ and a query's `delete()` run setters, validation, encryption and lifecycle
65
+ events, any of which may wait. Keep their `await`.
66
+ - **How.** SQLite runs a query in place. MySQL and Postgres run on Bun's
67
+ driver, held by a worker thread the caller waits on, so nothing else runs on
68
+ the calling thread while a query is in flight (the cost `bun:sqlite` always
69
+ had). `models: { execution: 'async' }` in the query-builder config makes
70
+ MySQL and Postgres reads promises again for an app that needs the event loop
71
+ free during queries; every read then has to be awaited.
72
+ - **Not covered.** The `db` query builder (`db.selectFrom(...)`) and
73
+ `transaction()` still return promises.
74
+
37
75
  ## Write behavior
38
76
 
39
77
  Ordinary create/update paths apply mass-assignment rules, declared validation,
@@ -107,10 +107,12 @@ if (User.where('active', true).exists()) dump(User.count())
107
107
  for (const post of Post.latest().limit(5).get()) dump(post.title)
108
108
  ```
109
109
 
110
- The rule: outside a function, a call that returns a promise is waited for
111
- where it stands, and so is a promise a statement names (the value of a line,
112
- of a declaration, of an assignment). A rejection is thrown there, so
113
- `User.findOrFail(0)` fails the run it was written in.
110
+ A model read is a value everywhere, in app code as well as here (see
111
+ `stacks-orm`). What a session adds is the rest: outside a function, a call
112
+ that returns a promise is waited for where it stands, and so is a promise a
113
+ statement names (the value of a line, of a declaration, of an assignment). So
114
+ a write (`User.create(...)`), a `fetch` or a job dispatch reads the same way a
115
+ query does. A rejection is thrown there.
114
116
 
115
117
  - **Inside a function nothing changes.** `await` there is yours to write:
116
118
  `users.map(async user => await user.posts())`.
@@ -6,7 +6,7 @@ interface DashboardStatDefinition {
6
6
  title: string
7
7
  icon: string
8
8
  iconBg: string
9
- count: () => Promise<number>
9
+ count: () => number | Promise<number>
10
10
  /** False when the model's feature is off, so the card is left out. */
11
11
  available?: () => boolean
12
12
  }
@@ -3,7 +3,8 @@ import type { ReadableRecord } from '@stacksjs/orm'
3
3
  export type KanbanModelRecord = ReadableRecord
4
4
 
5
5
  export interface RefreshableKanbanModelRecord extends KanbanModelRecord {
6
- fresh: () => Promise<KanbanModelRecord | null>
6
+ /** A read answers in place; a caller's own record type may still hand back a promise. */
7
+ fresh: () => KanbanModelRecord | null | Promise<KanbanModelRecord | null>
7
8
  }
8
9
 
9
10
  export async function refreshModel(record: RefreshableKanbanModelRecord): Promise<KanbanModelRecord> {
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.561",
5
+ "version": "0.75.562",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.561",
5
+ "version": "0.75.562",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,10 +45,10 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.561",
48
+ "@stacksjs/mobile": "0.75.562",
49
49
  "@stacksjs/sanitizer": "^0.2.864",
50
50
  "@stacksjs/stx": "^0.2.864",
51
- "@stacksjs/strings": "0.75.561",
51
+ "@stacksjs/strings": "0.75.562",
52
52
  "@xterm/addon-fit": "^0.11.0",
53
53
  "@xterm/xterm": "^6.0.0",
54
54
  "ts-qr-codes": "^0.1.8"