@stacksjs/orm 0.74.1 → 0.74.2

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 (53) hide show
  1. package/dist/auto-crud.d.ts +30 -0
  2. package/dist/generate-database-schema.d.ts +1 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.js +9 -9
  5. package/dist/migration-tables.d.ts +18 -0
  6. package/dist/models/AnalyticsEvent.ts +5 -0
  7. package/dist/models/Content/Menu.ts +5 -1
  8. package/dist/models/Content/MenuItem.ts +6 -1
  9. package/dist/models/Content/Page.ts +5 -1
  10. package/dist/models/Content/Post.ts +5 -1
  11. package/dist/models/Content/Redirect.ts +5 -1
  12. package/dist/models/EmailIdempotency.ts +5 -0
  13. package/dist/models/EmailList.ts +6 -0
  14. package/dist/models/EmailSuppression.ts +5 -0
  15. package/dist/models/EmailWebhookEvent.ts +5 -0
  16. package/dist/models/Forms/Form.ts +5 -1
  17. package/dist/models/Forms/FormField.ts +6 -1
  18. package/dist/models/MailPreference.ts +5 -0
  19. package/dist/models/Request.ts +5 -0
  20. package/dist/models/SiteDomain.ts +5 -1
  21. package/dist/models/Tag.ts +6 -0
  22. package/dist/models/Team.ts +6 -1
  23. package/dist/models/User.ts +6 -1
  24. package/dist/models/commerce/Auction.ts +6 -0
  25. package/dist/models/commerce/AuctionItem.ts +6 -0
  26. package/dist/models/commerce/Cart.ts +6 -1
  27. package/dist/models/commerce/CartItem.ts +6 -1
  28. package/dist/models/commerce/Category.ts +6 -0
  29. package/dist/models/commerce/Coupon.ts +6 -0
  30. package/dist/models/commerce/DeliveryRoute.ts +6 -1
  31. package/dist/models/commerce/DeliveryStop.ts +6 -1
  32. package/dist/models/commerce/GiftCard.ts +6 -1
  33. package/dist/models/commerce/LicenseKey.ts +6 -1
  34. package/dist/models/commerce/LoyaltyReward.ts +6 -0
  35. package/dist/models/commerce/Manufacturer.ts +6 -0
  36. package/dist/models/commerce/Order.ts +6 -1
  37. package/dist/models/commerce/Payment.ts +6 -1
  38. package/dist/models/commerce/PrintDevice.ts +6 -0
  39. package/dist/models/commerce/Product.ts +6 -0
  40. package/dist/models/commerce/ProductUnit.ts +6 -0
  41. package/dist/models/commerce/ProductVariant.ts +6 -0
  42. package/dist/models/commerce/Review.ts +6 -1
  43. package/dist/models/commerce/ShippingMethod.ts +6 -0
  44. package/dist/models/commerce/ShippingRate.ts +6 -0
  45. package/dist/models/commerce/ShippingZone.ts +6 -0
  46. package/dist/models/commerce/TaxRate.ts +6 -0
  47. package/dist/models/commerce/Transaction.ts +6 -1
  48. package/dist/models/commerce/WaitlistProduct.ts +6 -1
  49. package/dist/models/commerce/WaitlistRestaurant.ts +6 -1
  50. package/dist/models/realtime/Websocket.ts +5 -0
  51. package/dist/ownership.d.ts +96 -0
  52. package/dist/routes.js +1 -1
  53. package/package.json +21 -21
@@ -57,6 +57,36 @@ export declare function teamOwnershipField(model: {
57
57
  attributes?: Record<string, unknown>
58
58
  belongsTo?: unknown[]
59
59
  } | null | undefined): string | null;
60
+ /**
61
+ * Resolve the database column used for automatic per-user ownership.
62
+ *
63
+ * The same principle `teamOwnershipField` applies to tenants, applied to the
64
+ * rows a single caller owns: a model carrying `user_id` (declared, or created
65
+ * by a `belongsTo: ['User']` relation during model-driven migration) has a
66
+ * per-row owner already, so it does not need to repeat that fact as an
67
+ * `ownership` config just to get API isolation.
68
+ *
69
+ * Ten of the framework's own models are in this shape - Card, Comment,
70
+ * Notification, Subscriber and friends - and every one of them published
71
+ * mutating routes that any authenticated caller could point at any row
72
+ * (stacksjs/stacks#2375).
73
+ */
74
+ export declare function userOwnershipField(model: {
75
+ attributes?: Record<string, unknown>
76
+ belongsTo?: unknown[]
77
+ } | null | undefined): string | null;
78
+ /**
79
+ * A model that has declared, in as many words, that its rows have no per-caller
80
+ * owner: `ownership: false`.
81
+ *
82
+ * This is what separates "considered, and there is genuinely nothing to scope
83
+ * by" - a public catalog table - from "nobody thought about it", which is the
84
+ * state `security.api.rowScoping: 'deny'` refuses to generate writes for. The
85
+ * two were indistinguishable before, which is why denying by default needed
86
+ * this to exist first: without it the safe default also punishes every model
87
+ * that is legitimately unscoped.
88
+ */
89
+ export declare function ownershipDeclaredUnscoped(model: { ownership?: unknown } | null | undefined): boolean;
60
90
  /**
61
91
  * Remove every client spelling of an ownership field, then apply the trusted
62
92
  * value resolved from the authenticated request. Array ownership is used for
@@ -16,6 +16,7 @@ export declare interface GenerateSchemaOptions {
16
16
  dryRun?: boolean
17
17
  target?: SchemaTarget
18
18
  dialect?: 'sqlite' | 'mysql' | 'postgres'
19
+ migrationsDir?: string | false
19
20
  }
20
21
  export declare interface GenerateSchemaResult {
21
22
  outFile: string
package/dist/index.d.ts CHANGED
@@ -280,6 +280,9 @@ export { createLikeableMethods } from './traits/likeable';
280
280
  // `@stacksjs/auth`'s './rbac-store-bqb' for back-compat; `mapWriteError`
281
281
  // powers the auto-CRUD store/update 409 mapping.
282
282
  export { filterFillable, getWritableFields, isUniqueViolation, mapWriteError, toSnakeCaseKeys } from './auto-crud';
283
+ // Ready-made `ownership` resolvers for models whose owner is one hop away
284
+ // (stacksjs/stacks#2375).
285
+ export { customerOwnership, parentOwnership, selfOwnership, siteOwnership, teamMembershipOwnership } from './ownership';
283
286
  export * from './batch-loader';
284
287
  export * from './db';
285
288
  export * from './subquery';