@supatype/cli 0.3.4 → 0.3.6

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 (119) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +168 -158
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/CHANGELOG.md +36 -0
  5. package/dist/adopt-walkthrough.d.ts +40 -0
  6. package/dist/adopt-walkthrough.d.ts.map +1 -0
  7. package/dist/adopt-walkthrough.js +113 -0
  8. package/dist/adopt-walkthrough.js.map +1 -0
  9. package/dist/cli-version-embedded.js +1 -1
  10. package/dist/commands/admin.d.ts.map +1 -1
  11. package/dist/commands/admin.js +7 -16
  12. package/dist/commands/admin.js.map +1 -1
  13. package/dist/commands/adopt.d.ts.map +1 -1
  14. package/dist/commands/adopt.js +5 -6
  15. package/dist/commands/adopt.js.map +1 -1
  16. package/dist/commands/db.js +3 -3
  17. package/dist/commands/db.js.map +1 -1
  18. package/dist/commands/deploy.d.ts.map +1 -1
  19. package/dist/commands/deploy.js +7 -4
  20. package/dist/commands/deploy.js.map +1 -1
  21. package/dist/commands/dev.d.ts.map +1 -1
  22. package/dist/commands/dev.js +20 -5
  23. package/dist/commands/dev.js.map +1 -1
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/doctor.js +5 -7
  26. package/dist/commands/doctor.js.map +1 -1
  27. package/dist/commands/init.js +1 -1
  28. package/dist/commands/init.js.map +1 -1
  29. package/dist/commands/migrate.d.ts.map +1 -1
  30. package/dist/commands/migrate.js +6 -3
  31. package/dist/commands/migrate.js.map +1 -1
  32. package/dist/commands/push.d.ts.map +1 -1
  33. package/dist/commands/push.js +10 -6
  34. package/dist/commands/push.js.map +1 -1
  35. package/dist/commands/seed.js +2 -2
  36. package/dist/commands/seed.js.map +1 -1
  37. package/dist/dev-compose.d.ts +42 -0
  38. package/dist/dev-compose.d.ts.map +1 -1
  39. package/dist/dev-compose.js +116 -71
  40. package/dist/dev-compose.js.map +1 -1
  41. package/dist/dev-db-reset.d.ts +19 -0
  42. package/dist/dev-db-reset.d.ts.map +1 -0
  43. package/dist/dev-db-reset.js +75 -0
  44. package/dist/dev-db-reset.js.map +1 -0
  45. package/dist/dev-initial-push.d.ts +37 -0
  46. package/dist/dev-initial-push.d.ts.map +1 -0
  47. package/dist/dev-initial-push.js +91 -0
  48. package/dist/dev-initial-push.js.map +1 -0
  49. package/dist/dev-ports.d.ts.map +1 -1
  50. package/dist/dev-ports.js +1 -1
  51. package/dist/dev-ports.js.map +1 -1
  52. package/dist/diff-output.d.ts +2 -2
  53. package/dist/diff-output.d.ts.map +1 -1
  54. package/dist/diff-output.js +1 -1
  55. package/dist/diff-output.js.map +1 -1
  56. package/dist/engine-client.d.ts +5 -1
  57. package/dist/engine-client.d.ts.map +1 -1
  58. package/dist/engine-client.js +8 -6
  59. package/dist/engine-client.js.map +1 -1
  60. package/dist/engine-push-output.d.ts +10 -0
  61. package/dist/engine-push-output.d.ts.map +1 -1
  62. package/dist/engine-push-output.js +12 -0
  63. package/dist/engine-push-output.js.map +1 -1
  64. package/dist/{seed-connection.d.ts → host-database.d.ts} +20 -10
  65. package/dist/host-database.d.ts.map +1 -0
  66. package/dist/{seed-connection.js → host-database.js} +40 -14
  67. package/dist/host-database.js.map +1 -0
  68. package/dist/resolve-target.d.ts +2 -2
  69. package/dist/resolve-target.d.ts.map +1 -1
  70. package/dist/resolve-target.js +15 -11
  71. package/dist/resolve-target.js.map +1 -1
  72. package/dist/retired-no-cache.d.ts +18 -0
  73. package/dist/retired-no-cache.d.ts.map +1 -0
  74. package/dist/retired-no-cache.js +21 -0
  75. package/dist/retired-no-cache.js.map +1 -0
  76. package/dist/self-host-compose.d.ts +6 -0
  77. package/dist/self-host-compose.d.ts.map +1 -1
  78. package/dist/self-host-compose.js +9 -3
  79. package/dist/self-host-compose.js.map +1 -1
  80. package/dist/type-extractor.d.ts.map +1 -1
  81. package/dist/type-extractor.js +31 -25
  82. package/dist/type-extractor.js.map +1 -1
  83. package/package.json +2 -2
  84. package/src/adopt-walkthrough.ts +142 -0
  85. package/src/cli-version-embedded.ts +1 -1
  86. package/src/commands/admin.ts +7 -20
  87. package/src/commands/adopt.ts +5 -6
  88. package/src/commands/db.ts +3 -3
  89. package/src/commands/deploy.ts +7 -4
  90. package/src/commands/dev.ts +22 -6
  91. package/src/commands/doctor.ts +5 -7
  92. package/src/commands/init.ts +1 -1
  93. package/src/commands/migrate.ts +7 -4
  94. package/src/commands/push.ts +28 -10
  95. package/src/commands/seed.ts +2 -2
  96. package/src/dev-compose.ts +166 -77
  97. package/src/dev-db-reset.ts +95 -0
  98. package/src/dev-initial-push.ts +134 -0
  99. package/src/dev-ports.ts +1 -1
  100. package/src/diff-output.ts +2 -2
  101. package/src/engine-client.ts +5 -4
  102. package/src/engine-push-output.ts +19 -0
  103. package/src/{seed-connection.ts → host-database.ts} +42 -12
  104. package/src/resolve-target.ts +20 -14
  105. package/src/retired-no-cache.ts +27 -0
  106. package/src/self-host-compose.ts +10 -3
  107. package/src/type-extractor.ts +39 -42
  108. package/tests/adopt-result.test.ts +27 -0
  109. package/tests/adopt-walkthrough.test.ts +129 -0
  110. package/tests/dev-db-reset.test.ts +162 -0
  111. package/tests/dev-initial-push.test.ts +142 -0
  112. package/tests/engine-push-output.test.ts +30 -1
  113. package/tests/host-connection-targets.test.ts +84 -0
  114. package/tests/{seed-connection.test.ts → host-database.test.ts} +33 -15
  115. package/tests/retired-no-cache.test.ts +46 -0
  116. package/tests/type-extractor.test.ts +80 -0
  117. package/tsconfig.tsbuildinfo +1 -1
  118. package/dist/seed-connection.d.ts.map +0 -1
  119. package/dist/seed-connection.js.map +0 -1
@@ -300,6 +300,50 @@ export type Post = Model<{
300
300
  expect(hero).toMatchObject({ kind: "image", bucket: "covers", accessMode: "public" })
301
301
  })
302
302
 
303
+ // A bucket has the same four operations a model has, each its own rule. `update` used to be
304
+ // skipped without a word, so an overwrite rule the author wrote was simply never enforced.
305
+ function bucketWithAccess(access: string): string {
306
+ const dir = mkdtempSync(join(tmpdir(), "supatype-bucket-rules-"))
307
+ dirs.push(dir)
308
+ const schemaPath = join(dir, "schema.ts")
309
+ writeFileSync(
310
+ schemaPath,
311
+ `
312
+ import type { Model, UUID, Bucket, BucketPublic, BucketLoggedIn, BucketOwner, FileAsset } from "@supatype/types"
313
+
314
+ export type avatars = Bucket<"avatars", { accessMode: "public"; access: ${access} }>
315
+
316
+ export type Profile = Model<{
317
+ id: UUID
318
+ avatar: FileAsset<avatars>
319
+ }>
320
+ `,
321
+ "utf8",
322
+ )
323
+ return schemaPath
324
+ }
325
+
326
+ it("extracts all four bucket rules, update included", () => {
327
+ const schemaPath = bucketWithAccess(
328
+ "{ read: BucketPublic; create: BucketLoggedIn; update: BucketOwner; delete: BucketOwner }",
329
+ )
330
+ const ast = extractSchemaAstFromTypes(schemaPath, join(schemaPath, ".."))
331
+ const b = ast?.storageBuckets?.find((x) => x.id === "avatars")
332
+ expect(b?.access).toEqual({
333
+ read: { type: "public" },
334
+ create: { type: "authenticated" },
335
+ update: { type: "owner", field: "owner_id" },
336
+ delete: { type: "owner", field: "owner_id" },
337
+ })
338
+ })
339
+
340
+ it("refuses a bucket rule key that is not an operation, rather than dropping it", () => {
341
+ const schemaPath = bucketWithAccess("{ read: BucketPublic; remove: BucketOwner }")
342
+ expect(() => extractSchemaAstFromTypes(schemaPath, join(schemaPath, ".."))).toThrow(
343
+ /Bucket "avatars": `remove` is not a bucket rule\. Use read, create, update or delete\./,
344
+ )
345
+ })
346
+
303
347
  it("extracts accessMode custom and s3BucketPolicy string", () => {
304
348
  const dir = mkdtempSync(join(tmpdir(), "supatype-bucket-custom-"))
305
349
  dirs.push(dir)
@@ -556,6 +600,42 @@ export type Config = Model<{
556
600
  expect(config?.options.singleton).toBe(true)
557
601
  })
558
602
 
603
+ it("carries a model's label overrides to the engine as options", () => {
604
+ // Presentation only: the engine passes these to Studio, which otherwise inflects the type
605
+ // name and cannot know that "Places of Interest" has its noun first.
606
+ const dir = mkdtempSync(join(tmpdir(), "supatype-model-labels-"))
607
+ dirs.push(dir)
608
+ const schemaPath = join(dir, "schema.ts")
609
+ writeFileSync(
610
+ schemaPath,
611
+ `
612
+ import type { Model, UUID, Public } from "@supatype/types"
613
+
614
+ export type PlacesOfInterest = Model<{
615
+ id: UUID
616
+ }, {
617
+ label: "Place of Interest"
618
+ labelPlural: "Places of Interest"
619
+ access: { read: Public }
620
+ }>
621
+
622
+ export type Post = Model<{
623
+ id: UUID
624
+ }, {
625
+ access: { read: Public }
626
+ }>
627
+ `,
628
+ "utf8",
629
+ )
630
+
631
+ const ast = extractSchemaAstFromTypes(schemaPath, dir)
632
+ const places = ast?.models.find((m) => m.name === "PlacesOfInterest")
633
+ expect(places?.options).toMatchObject({ label: "Place of Interest", labelPlural: "Places of Interest" })
634
+ const post = ast?.models.find((m) => m.name === "Post")
635
+ expect(post?.options).not.toHaveProperty("label")
636
+ expect(post?.options).not.toHaveProperty("labelPlural")
637
+ })
638
+
559
639
  it("infers timestamps from WithTimestamps wrapper", () => {
560
640
  const dir = mkdtempSync(join(tmpdir(), "supatype-timestamps-"))
561
641
  dirs.push(dir)