@crombolo/server 0.0.0-stage → 0.10.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +69 -0
  3. package/package.json +41 -4
  4. package/src/access.ts +114 -0
  5. package/src/adapters/assistant.ts +229 -0
  6. package/src/adapters/blueprints.ts +163 -0
  7. package/src/adapters/bundles.ts +507 -0
  8. package/src/adapters/content.ts +783 -0
  9. package/src/adapters/dictionary.ts +76 -0
  10. package/src/adapters/documents.ts +637 -0
  11. package/src/adapters/elements.ts +403 -0
  12. package/src/adapters/file-system.ts +195 -0
  13. package/src/adapters/media.ts +347 -0
  14. package/src/adapters/member-groups.ts +90 -0
  15. package/src/adapters/members.ts +261 -0
  16. package/src/adapters/public-access.ts +116 -0
  17. package/src/adapters/redirects.ts +73 -0
  18. package/src/adapters/references.ts +67 -0
  19. package/src/adapters/schema-files.ts +204 -0
  20. package/src/adapters/schema-proposals.ts +180 -0
  21. package/src/adapters/template-files.ts +58 -0
  22. package/src/adapters/template-query.ts +127 -0
  23. package/src/adapters/users.ts +963 -0
  24. package/src/assistant.ts +487 -0
  25. package/src/backup.ts +52 -0
  26. package/src/bundle-install.ts +417 -0
  27. package/src/bundle-sections.ts +424 -0
  28. package/src/bundle-tables.ts +161 -0
  29. package/src/bundles.ts +609 -0
  30. package/src/component-snippets.ts +163 -0
  31. package/src/components.ts +266 -0
  32. package/src/config.ts +556 -0
  33. package/src/content-type-udt.ts +256 -0
  34. package/src/database.ts +148 -0
  35. package/src/diagnostics.ts +143 -0
  36. package/src/dictionary-transfer.ts +123 -0
  37. package/src/domains.ts +384 -0
  38. package/src/editor-types.ts +108 -0
  39. package/src/email-http.ts +79 -0
  40. package/src/email-notice.ts +36 -0
  41. package/src/email-postmark.ts +78 -0
  42. package/src/email-resend.ts +69 -0
  43. package/src/email-ses.ts +307 -0
  44. package/src/email.ts +402 -0
  45. package/src/extensions-notice.ts +35 -0
  46. package/src/file-intake.ts +84 -0
  47. package/src/form-files.ts +241 -0
  48. package/src/form-submit.ts +397 -0
  49. package/src/form-workflows.ts +397 -0
  50. package/src/forms.ts +170 -0
  51. package/src/git-github.ts +171 -0
  52. package/src/git-routes.ts +154 -0
  53. package/src/git.ts +88 -0
  54. package/src/imaging.ts +434 -0
  55. package/src/index.ts +65 -0
  56. package/src/jobs.ts +140 -0
  57. package/src/listen.ts +36 -0
  58. package/src/log-expressions.ts +524 -0
  59. package/src/log-viewer.ts +190 -0
  60. package/src/logging.ts +126 -0
  61. package/src/marketplace.ts +382 -0
  62. package/src/media-files.ts +276 -0
  63. package/src/media-store-azure.ts +218 -0
  64. package/src/media-store-s3.ts +113 -0
  65. package/src/media-store.ts +248 -0
  66. package/src/member-auth.ts +384 -0
  67. package/src/models-builder.ts +106 -0
  68. package/src/no-nodes.ts +64 -0
  69. package/src/not-implemented.ts +44 -0
  70. package/src/oembed.ts +144 -0
  71. package/src/ports.ts +553 -0
  72. package/src/redirects.ts +132 -0
  73. package/src/schema-classify.ts +82 -0
  74. package/src/schema-store.ts +145 -0
  75. package/src/schema.ts +388 -0
  76. package/src/seo.ts +371 -0
  77. package/src/server-events.ts +131 -0
  78. package/src/server.ts +1642 -0
  79. package/src/status.ts +275 -0
  80. package/src/tar.ts +85 -0
  81. package/src/udt.ts +168 -0
  82. package/src/value-schemas.ts +64 -0
  83. package/src/view-runtime.ts +42 -0
  84. package/src/zip.ts +152 -0
  85. package/README.md +0 -3
package/src/zip.ts ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * A minimal zip writer, because a created package is a zip and nothing else
3
+ * here needs one (`docs/bundles.md`).
4
+ *
5
+ * No dependency: `node:zlib` provides `deflateRawSync` and `crc32`, which is
6
+ * everything the format needs. Entries are written in the order given, each
7
+ * stored if deflating does not make it smaller, and timestamps are fixed at the
8
+ * epoch the format starts from so the same selection zips to the same bytes.
9
+ */
10
+ import { crc32, deflateRawSync } from 'node:zlib'
11
+
12
+ export interface ZipEntry {
13
+ /** The path inside the archive, `/`-separated and never absolute. */
14
+ path: string
15
+ bytes: Uint8Array
16
+ }
17
+
18
+ const LOCAL_HEADER = 0x04034b50
19
+ const CENTRAL_HEADER = 0x02014b50
20
+ const END_OF_CENTRAL = 0x06054b50
21
+
22
+ /** Deflate, or store when deflating gains nothing — as every zip writer does. */
23
+ const STORED = 0
24
+ const DEFLATED = 8
25
+
26
+ /**
27
+ * 1980-01-01 00:00:00, the earliest the DOS field can express. A real time
28
+ * would make the bytes depend on when the download happened, and nothing reads
29
+ * these timestamps.
30
+ */
31
+ const DOS_DATE = 0x0021
32
+ const DOS_TIME = 0x0000
33
+
34
+ /** Bit 11: the name is UTF-8, so a non-ASCII path survives the round trip. */
35
+ const UTF8_FLAG = 0x0800
36
+
37
+ class Writer {
38
+ #chunks: Uint8Array[] = []
39
+ #length = 0
40
+
41
+ get length(): number {
42
+ return this.#length
43
+ }
44
+
45
+ bytes(value: Uint8Array): void {
46
+ this.#chunks.push(value)
47
+ this.#length += value.length
48
+ }
49
+
50
+ u16(value: number): void {
51
+ const view = new Uint8Array(2)
52
+ new DataView(view.buffer).setUint16(0, value, true)
53
+ this.bytes(view)
54
+ }
55
+
56
+ u32(value: number): void {
57
+ const view = new Uint8Array(4)
58
+ new DataView(view.buffer).setUint32(0, value >>> 0, true)
59
+ this.bytes(view)
60
+ }
61
+
62
+ concat(): Uint8Array<ArrayBuffer> {
63
+ const out = new Uint8Array(this.#length)
64
+ let offset = 0
65
+ for (const chunk of this.#chunks) {
66
+ out.set(chunk, offset)
67
+ offset += chunk.length
68
+ }
69
+ return out
70
+ }
71
+ }
72
+
73
+ interface Compressed {
74
+ method: number
75
+ crc: number
76
+ deflated: Uint8Array
77
+ size: number
78
+ }
79
+
80
+ function compress(bytes: Uint8Array): Compressed {
81
+ const crc = crc32(bytes) >>> 0
82
+ if (bytes.length === 0) return { method: STORED, crc, deflated: bytes, size: 0 }
83
+ const deflated = new Uint8Array(deflateRawSync(bytes))
84
+ return deflated.length < bytes.length
85
+ ? { method: DEFLATED, crc, deflated, size: bytes.length }
86
+ : { method: STORED, crc, deflated: bytes, size: bytes.length }
87
+ }
88
+
89
+ /**
90
+ * The archive as one buffer. Package zips are a schema directory, some views
91
+ * and a media library's worth of images — large enough to care about, small
92
+ * enough that streaming would buy nothing but complexity.
93
+ */
94
+ export function writeZip(entries: readonly ZipEntry[]): Uint8Array<ArrayBuffer> {
95
+ const encoder = new TextEncoder()
96
+ const body = new Writer()
97
+ const central = new Writer()
98
+
99
+ for (const entry of entries) {
100
+ const name = encoder.encode(entry.path)
101
+ const { method, crc, deflated, size } = compress(entry.bytes)
102
+ const offset = body.length
103
+
104
+ body.u32(LOCAL_HEADER)
105
+ body.u16(20)
106
+ body.u16(UTF8_FLAG)
107
+ body.u16(method)
108
+ body.u16(DOS_TIME)
109
+ body.u16(DOS_DATE)
110
+ body.u32(crc)
111
+ body.u32(deflated.length)
112
+ body.u32(size)
113
+ body.u16(name.length)
114
+ body.u16(0)
115
+ body.bytes(name)
116
+ body.bytes(deflated)
117
+
118
+ central.u32(CENTRAL_HEADER)
119
+ central.u16(20)
120
+ central.u16(20)
121
+ central.u16(UTF8_FLAG)
122
+ central.u16(method)
123
+ central.u16(DOS_TIME)
124
+ central.u16(DOS_DATE)
125
+ central.u32(crc)
126
+ central.u32(deflated.length)
127
+ central.u32(size)
128
+ central.u16(name.length)
129
+ central.u16(0)
130
+ central.u16(0)
131
+ central.u16(0)
132
+ central.u16(0)
133
+ // 0o100644 in the high word: a regular file, readable, as unzip expects.
134
+ central.u32(0o100644 << 16)
135
+ central.u32(offset)
136
+ central.bytes(name)
137
+ }
138
+
139
+ const out = new Writer()
140
+ out.bytes(body.concat())
141
+ const centralOffset = out.length
142
+ out.bytes(central.concat())
143
+ out.u32(END_OF_CENTRAL)
144
+ out.u16(0)
145
+ out.u16(0)
146
+ out.u16(entries.length)
147
+ out.u16(entries.length)
148
+ out.u32(central.length)
149
+ out.u32(centralOffset)
150
+ out.u16(0)
151
+ return out.concat()
152
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.