alinea 0.6.2 → 0.6.4

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 (41) hide show
  1. package/dist/backend/Database.js +36 -17
  2. package/dist/backend/Handler.d.ts +1 -1
  3. package/dist/backend/Handler.js +3 -3
  4. package/dist/backend/Previews.d.ts +3 -7
  5. package/dist/backend/util/JWTPreviews.d.ts +4 -3
  6. package/dist/chunks/{chunk-FO7WYIGB.js → chunk-TFVRT7UJ.js} +1 -12
  7. package/dist/chunks/chunk-UJJSVROY.js +3967 -0
  8. package/dist/cli/Init.js +1 -1
  9. package/dist/cli/Serve.js +17 -3
  10. package/dist/cli/bin.js +1 -1
  11. package/dist/cli/generate/GenerateDashboard.js +1 -1
  12. package/dist/cli/serve/CreateLocalServer.d.ts +2 -1
  13. package/dist/cli/serve/CreateLocalServer.js +2 -2
  14. package/dist/cli/serve/GitHistory.d.ts +2 -2
  15. package/dist/cli/serve/GitHistory.js +3 -3968
  16. package/dist/cloud/server/CloudAuthServer.js +1 -1
  17. package/dist/cloud/server/CloudDebugHandler.js +4 -1
  18. package/dist/core/Auth.js +2 -1
  19. package/dist/core/Entry.d.ts +1 -1
  20. package/dist/core/EntryRecord.d.ts +2 -2
  21. package/dist/core/EntryRecord.js +1 -2
  22. package/dist/core/EntryRow.d.ts +1 -1
  23. package/dist/core/EntryRow.js +1 -1
  24. package/dist/core/User.d.ts +4 -0
  25. package/dist/core/User.js +10 -0
  26. package/dist/core/driver/NextDriver.d.ts +8 -1
  27. package/dist/core/driver/NextDriver.server.js +44 -6
  28. package/dist/core/driver/NextPreviews.d.ts +9 -1
  29. package/dist/core/driver/NextPreviews.js +238 -3
  30. package/dist/dashboard/Routes.d.ts +20 -18
  31. package/dist/dashboard/Routes.js +46 -1
  32. package/dist/dashboard/atoms/DashboardAtoms.js +7 -2
  33. package/dist/dashboard/atoms/LocationAtoms.d.ts +1 -0
  34. package/dist/dashboard/atoms/LocationAtoms.js +6 -1
  35. package/dist/dashboard/atoms/RouterAtoms.d.ts +1 -1
  36. package/dist/dashboard/atoms/RouterAtoms.js +2 -1
  37. package/dist/dashboard/hook/UseUploads.js +1 -1
  38. package/dist/dashboard/view/entry/NewEntry.js +1 -1
  39. package/dist/ui/icons/IcRoundExitToApp.d.ts +2 -0
  40. package/dist/ui/icons/IcRoundExitToApp.js +26 -0
  41. package/package.json +1 -12
@@ -20,6 +20,7 @@ import {
20
20
  Type,
21
21
  Workspace,
22
22
  createId,
23
+ slugify,
23
24
  unreachable
24
25
  } from "alinea/core";
25
26
  import { entryInfo, entryUrl } from "alinea/core/EntryFilenames";
@@ -444,7 +445,7 @@ ${JSON.stringify(mutation)}`
444
445
  workspace: meta.workspace,
445
446
  root: meta.root,
446
447
  filePath: meta.filePath,
447
- seeded: Boolean(seed || alineaMeta.seeded || false),
448
+ seeded: seed?.filePath ?? null,
448
449
  modifiedAt: Date.now(),
449
450
  // file.modifiedAt,
450
451
  active: false,
@@ -478,10 +479,11 @@ ${JSON.stringify(mutation)}`
478
479
  const target = locale ? `/${locale}` : "/";
479
480
  while (pages.length > 0) {
480
481
  const [pagePath, page] = pages.shift();
482
+ const path = pagePath.split("/").map(slugify).join("/");
481
483
  if (!PageSeed.isPageSeed(page))
482
484
  continue;
483
485
  const { type } = PageSeed.data(page);
484
- const filePath = paths.join(target, pagePath) + ".json";
486
+ const filePath = paths.join(target, path) + ".json";
485
487
  const typeName = typeNames.get(type);
486
488
  if (!typeName)
487
489
  continue;
@@ -493,7 +495,7 @@ ${JSON.stringify(mutation)}`
493
495
  page
494
496
  });
495
497
  const children = entries(page).map(
496
- ([childPath, child]) => [paths.join(pagePath, childPath), child]
498
+ ([childPath, child]) => [paths.join(path, childPath), child]
497
499
  );
498
500
  pages.push(...children);
499
501
  }
@@ -511,7 +513,6 @@ ${JSON.stringify(mutation)}`
511
513
  const seenSeeds = /* @__PURE__ */ new Set();
512
514
  const inserted = [];
513
515
  for await (const file of source.entries()) {
514
- const seed = this.seed.get(file.filePath);
515
516
  const fileHash = await createFileHash(file.contents);
516
517
  const exists2 = await query(
517
518
  EntryRow({
@@ -519,20 +520,29 @@ ${JSON.stringify(mutation)}`
519
520
  filePath: file.filePath,
520
521
  workspace: file.workspace,
521
522
  root: file.root
522
- }).select(EntryRow.versionId).maybeFirst()
523
+ }).select({
524
+ versionId: EntryRow.versionId,
525
+ seeded: EntryRow.seeded
526
+ }).maybeFirst()
523
527
  );
524
- if (seed) {
525
- seenSeeds.add(seed.filePath);
526
- }
527
528
  if (exists2) {
528
- seenVersions.push(exists2);
529
+ seenVersions.push(exists2.versionId);
530
+ if (exists2.seeded)
531
+ seenSeeds.add(exists2.seeded);
532
+ else
533
+ seenSeeds.add(file.filePath);
529
534
  continue;
530
535
  }
531
536
  try {
532
537
  const raw = JsonLoader.parse(this.config.schema, file.contents);
533
- const entry = this.computeEntry(EntryRecord(raw), file, seed);
534
- if (entry.seeded && entry.phase === EntryPhase.Published && !seed)
535
- throw new Error(`seed entry is missing from config`);
538
+ const record = EntryRecord(raw);
539
+ const seeded = record[META_KEY]?.seeded;
540
+ const seed = typeof seeded === "string" ? this.seed.get(seeded) : void 0;
541
+ const entry = this.computeEntry(record, file, seed);
542
+ if (seed)
543
+ seenSeeds.add(seed.filePath);
544
+ else
545
+ seenSeeds.add(file.filePath);
536
546
  await query(
537
547
  EntryRow({ entryId: entry.entryId, phase: entry.phase }).delete()
538
548
  );
@@ -547,22 +557,32 @@ ${JSON.stringify(mutation)}`
547
557
  console.log(`> skipped ${file.filePath} \u2014 ${e2.message}`);
548
558
  }
549
559
  }
550
- const seedPaths = Array.from(this.seed.keys());
551
- for (const seedPath of seedPaths) {
560
+ const stableI18nIds = /* @__PURE__ */ new Map();
561
+ for (const [seedPath, seed] of this.seed.entries()) {
552
562
  if (seenSeeds.has(seedPath))
553
563
  continue;
554
- const seed = this.seed.get(seedPath);
555
564
  const { type, partial } = PageSeed.data(seed.page);
556
565
  const typeName = typeNames.get(type);
557
566
  if (!typeName)
558
567
  continue;
568
+ const root = this.config.workspaces[seed.workspace][seed.root];
569
+ const { i18n } = Root.data(root);
570
+ let i18nId = createId();
571
+ if (i18n) {
572
+ const [, locale, ...rest] = seed.filePath.split("/");
573
+ const path = rest.join("/");
574
+ i18nId = stableI18nIds.get(path) ?? createId();
575
+ stableI18nIds.set(path, i18nId);
576
+ }
559
577
  const entry = this.computeEntry(
560
578
  {
561
579
  title: partial.title ?? "",
562
580
  [META_KEY]: {
563
581
  entryId: createId(),
582
+ i18nId,
564
583
  type: typeName,
565
- index: "a0"
584
+ index: "a0",
585
+ seeded: seed.filePath
566
586
  }
567
587
  },
568
588
  seed,
@@ -578,7 +598,6 @@ ${JSON.stringify(mutation)}`
578
598
  inserted.push(`${entry.entryId}.${entry.phase}`);
579
599
  publishSeed.push({
580
600
  ...withHash,
581
- seeded: true,
582
601
  title: void 0,
583
602
  data: {}
584
603
  });
@@ -40,7 +40,7 @@ export declare class Handler implements Resolver {
40
40
  entryId: string;
41
41
  phase: EntryPhase;
42
42
  type: string;
43
- seeded: boolean;
43
+ seeded: string | null;
44
44
  workspace: string;
45
45
  root: string;
46
46
  level: number;
@@ -43,7 +43,7 @@ var Handler = class {
43
43
  this.parsePreview.bind(this)
44
44
  );
45
45
  this.changes = new ChangeSetCreator(options.config);
46
- const auth = options.auth || Auth.anonymous();
46
+ const auth = options.auth ?? Auth.anonymous();
47
47
  this.connect = (ctx) => new HandlerConnection(this, ctx);
48
48
  this.router = createRouter(auth, this.connect);
49
49
  }
@@ -169,8 +169,8 @@ var HandlerConnection = class {
169
169
  const { previews } = this.handler.options;
170
170
  const user = this.ctx.user;
171
171
  if (!user)
172
- return previews.sign({ anonymous: true });
173
- return previews.sign({ sub: user.sub });
172
+ throw new Error("Unauthorized, user not available");
173
+ return previews.sign(user);
174
174
  }
175
175
  // Media
176
176
  prepareUpload(file) {
@@ -1,9 +1,5 @@
1
- export type PreviewTokenPayload = {
2
- sub: string;
3
- } | {
4
- anonymous: true;
5
- };
1
+ import { User } from 'alinea/core';
6
2
  export interface Previews {
7
- sign(data: PreviewTokenPayload): Promise<string>;
8
- verify(token: string): Promise<PreviewTokenPayload>;
3
+ sign(data: User): Promise<string>;
4
+ verify(token: string): Promise<User>;
9
5
  }
@@ -1,7 +1,8 @@
1
- import { PreviewTokenPayload, Previews } from '../Previews.js';
1
+ import { User } from 'alinea/core';
2
+ import { Previews } from '../Previews.js';
2
3
  export declare class JWTPreviews implements Previews {
3
4
  private secret;
4
5
  constructor(secret: string);
5
- sign(data: PreviewTokenPayload): Promise<string>;
6
- verify(token: string): Promise<PreviewTokenPayload>;
6
+ sign(data: User): Promise<string>;
7
+ verify(token: string): Promise<User>;
7
8
  }
@@ -2,7 +2,7 @@
2
2
  var package_default = {
3
3
  bin: "./dist/cli.js",
4
4
  name: "alinea",
5
- version: "0.6.2",
5
+ version: "0.6.4",
6
6
  license: "MIT",
7
7
  type: "module",
8
8
  scripts: {
@@ -39,17 +39,6 @@ var package_default = {
39
39
  files: [
40
40
  "dist"
41
41
  ],
42
- workspaces: [
43
- "apps/web",
44
- "apps/dev",
45
- "src/backend",
46
- "src/cli",
47
- "src/core",
48
- "src/dashboard",
49
- "src/ui",
50
- "src/auth/passwordless",
51
- "src/input/richtext"
52
- ],
53
42
  dependencies: {
54
43
  "@alinea/iso": "^0.3.1",
55
44
  "@alinea/sqlite-wasm": "^0.1.14",