@nuasite/cms-core 0.59.0 → 0.61.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.
- package/dist/types/byte-range.d.ts +15 -0
- package/dist/types/byte-range.d.ts.map +1 -0
- package/dist/types/collection-scanner.d.ts.map +1 -1
- package/dist/types/content-config-ast.d.ts.map +1 -1
- package/dist/types/core.d.ts +8 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/fs/node-fs.d.ts.map +1 -1
- package/dist/types/fs/staged.d.ts +65 -0
- package/dist/types/fs/staged.d.ts.map +1 -0
- package/dist/types/fs/types.d.ts +2 -0
- package/dist/types/fs/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -23
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/media/file-system.d.ts +15 -0
- package/dist/types/media/file-system.d.ts.map +1 -0
- package/dist/types/media/index.d.ts +2 -1
- package/dist/types/media/index.d.ts.map +1 -1
- package/dist/types/media/local.d.ts +0 -3
- package/dist/types/media/local.d.ts.map +1 -1
- package/dist/types/media/mime.d.ts +4 -0
- package/dist/types/media/mime.d.ts.map +1 -0
- package/dist/types/portable.d.ts +30 -0
- package/dist/types/portable.d.ts.map +1 -0
- package/dist/types/public-static-file.d.ts +11 -0
- package/dist/types/public-static-file.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/byte-range.ts +33 -0
- package/src/check.ts +2 -2
- package/src/collection-scanner.ts +5 -0
- package/src/content-config-ast.ts +1 -0
- package/src/core.ts +43 -21
- package/src/fs/node-fs.ts +18 -12
- package/src/fs/staged.ts +230 -0
- package/src/fs/types.ts +2 -0
- package/src/handlers/entry-ops.ts +1 -1
- package/src/index.ts +3 -125
- package/src/media/file-system.ts +133 -0
- package/src/media/index.ts +2 -1
- package/src/media/local.ts +1 -24
- package/src/media/mime.ts +23 -0
- package/src/media/project-images.ts +1 -1
- package/src/media/s3.ts +1 -1
- package/src/portable.ts +143 -0
- package/src/public-static-file.ts +42 -0
package/src/media/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { type ContemberStorageOptions, createContemberStorageAdapter } from './contember'
|
|
2
2
|
export { MEDIA_INVALID_FOLDER, MEDIA_INVALID_ID, MEDIA_NOT_FOUND, mediaErrorStatus } from './errors'
|
|
3
|
-
export {
|
|
3
|
+
export { createFileSystemStorageAdapter, type FileSystemStorageOptions } from './file-system'
|
|
4
|
+
export { getFileExtension, MIME_BY_EXT, mimeFromExt } from './mime'
|
|
4
5
|
export { isUnsafeFolder } from './names'
|
|
5
6
|
export { listProjectImages, type ListProjectImagesOptions, uploadsDirRelativeToRoot } from './project-images'
|
|
6
7
|
export { createS3StorageAdapter, type S3StorageOptions } from './s3'
|
package/src/media/local.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto'
|
|
|
3
3
|
import fs from 'node:fs/promises'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { MEDIA_INVALID_FOLDER, MEDIA_INVALID_ID, MEDIA_NOT_FOUND } from './errors'
|
|
6
|
+
import { getFileExtension, mimeFromExt } from './mime'
|
|
6
7
|
import { isUnsafeFolder } from './names'
|
|
7
8
|
|
|
8
9
|
export interface LocalStorageOptions {
|
|
@@ -227,27 +228,3 @@ export function createLocalStorageAdapter(options: LocalStorageOptions = {}): Me
|
|
|
227
228
|
},
|
|
228
229
|
}
|
|
229
230
|
}
|
|
230
|
-
|
|
231
|
-
export function getFileExtension(filename: string): string {
|
|
232
|
-
const parts = filename.split('.')
|
|
233
|
-
const ext = parts.length > 1 ? (parts.pop()?.toLowerCase() ?? '') : ''
|
|
234
|
-
return /^[a-z0-9]+$/.test(ext) ? ext : ''
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export const MIME_BY_EXT: Record<string, string> = {
|
|
238
|
-
'.jpg': 'image/jpeg',
|
|
239
|
-
'.jpeg': 'image/jpeg',
|
|
240
|
-
'.png': 'image/png',
|
|
241
|
-
'.gif': 'image/gif',
|
|
242
|
-
'.webp': 'image/webp',
|
|
243
|
-
'.avif': 'image/avif',
|
|
244
|
-
'.svg': 'image/svg+xml',
|
|
245
|
-
'.ico': 'image/x-icon',
|
|
246
|
-
'.mp4': 'video/mp4',
|
|
247
|
-
'.webm': 'video/webm',
|
|
248
|
-
'.pdf': 'application/pdf',
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function mimeFromExt(ext: string): string {
|
|
252
|
-
return MIME_BY_EXT[ext] ?? 'application/octet-stream'
|
|
253
|
-
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function getFileExtension(filename: string): string {
|
|
2
|
+
const parts = filename.split('.')
|
|
3
|
+
const ext = parts.length > 1 ? (parts.pop()?.toLowerCase() ?? '') : ''
|
|
4
|
+
return /^[a-z0-9]+$/.test(ext) ? ext : ''
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const MIME_BY_EXT: Record<string, string> = {
|
|
8
|
+
'.jpg': 'image/jpeg',
|
|
9
|
+
'.jpeg': 'image/jpeg',
|
|
10
|
+
'.png': 'image/png',
|
|
11
|
+
'.gif': 'image/gif',
|
|
12
|
+
'.webp': 'image/webp',
|
|
13
|
+
'.avif': 'image/avif',
|
|
14
|
+
'.svg': 'image/svg+xml',
|
|
15
|
+
'.ico': 'image/x-icon',
|
|
16
|
+
'.mp4': 'video/mp4',
|
|
17
|
+
'.webm': 'video/webm',
|
|
18
|
+
'.pdf': 'application/pdf',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function mimeFromExt(ext: string): string {
|
|
22
|
+
return MIME_BY_EXT[ext] ?? 'application/octet-stream'
|
|
23
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MediaItem } from '@nuasite/cms-types'
|
|
2
2
|
import type { CmsFileSystem } from '../fs/types'
|
|
3
|
-
import { MIME_BY_EXT, mimeFromExt } from './
|
|
3
|
+
import { MIME_BY_EXT, mimeFromExt } from './mime'
|
|
4
4
|
|
|
5
5
|
const IMAGE_EXTENSIONS = new Set(Object.entries(MIME_BY_EXT).filter(([, mime]) => mime.startsWith('image/')).map(([ext]) => ext))
|
|
6
6
|
|
package/src/media/s3.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { MediaFolderItem, MediaListResult, MediaStorageAdapter, MediaUpload
|
|
|
2
2
|
import { randomUUID } from 'node:crypto'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { MEDIA_INVALID_FOLDER, MEDIA_INVALID_ID } from './errors'
|
|
5
|
-
import { getFileExtension, mimeFromExt } from './
|
|
5
|
+
import { getFileExtension, mimeFromExt } from './mime'
|
|
6
6
|
import { hasDotSegment, isUnsafeFolder } from './names'
|
|
7
7
|
|
|
8
8
|
/*
|
package/src/portable.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything cms-core offers that runs without `node:fs`. The package root resolves here under the
|
|
3
|
+
* `workerd` condition; the default root adds the Node filesystem and the local media adapter.
|
|
4
|
+
*/
|
|
5
|
+
export { resolveAssetCandidates } from './asset-paths'
|
|
6
|
+
export {
|
|
7
|
+
analyzeAstroScript,
|
|
8
|
+
analyzeAstroSource,
|
|
9
|
+
type AstroCollectionBinding,
|
|
10
|
+
type AstroContentAccessor,
|
|
11
|
+
type AstroContentCall,
|
|
12
|
+
type AstroSourceAnalysis,
|
|
13
|
+
type AstroSourceImport,
|
|
14
|
+
} from './astro-source-analysis'
|
|
15
|
+
export { type ByteRange, resolveByteRange } from './byte-range'
|
|
16
|
+
export { checkContent, type CheckContentOptions, type CheckFinding, type CheckReport, type CheckSeverity, formatCheckReport } from './check'
|
|
17
|
+
export {
|
|
18
|
+
collectionKind,
|
|
19
|
+
entryStem,
|
|
20
|
+
loadCollections,
|
|
21
|
+
type LoadedCollection,
|
|
22
|
+
type LoadedCollections,
|
|
23
|
+
type LoadedEntry,
|
|
24
|
+
normalizeBase,
|
|
25
|
+
parseEntry,
|
|
26
|
+
} from './check-entries'
|
|
27
|
+
export { checkAgainstSchemas, type LiveCheckInput } from './check-live'
|
|
28
|
+
export { checkFieldShapes, type ShapeCheckInput } from './check-shape'
|
|
29
|
+
export { checkEditorWrites, type WriteCheckInput } from './check-write'
|
|
30
|
+
export { collectionScanReport, scanCollections } from './collection-scanner'
|
|
31
|
+
export { scanComponentDefinitions } from './component-registry'
|
|
32
|
+
export {
|
|
33
|
+
classifyEmptyContentConfig,
|
|
34
|
+
CONTENT_CONFIG_PATHS,
|
|
35
|
+
type ContentConfigRead,
|
|
36
|
+
type DeclaredCollection,
|
|
37
|
+
type EmptyContentConfigReason,
|
|
38
|
+
type ParseCache,
|
|
39
|
+
parseConfigSource,
|
|
40
|
+
parseContentConfig,
|
|
41
|
+
type ParsedCollection,
|
|
42
|
+
type ParsedConfig,
|
|
43
|
+
type ParsedField,
|
|
44
|
+
type ParsedReference,
|
|
45
|
+
readContentConfig,
|
|
46
|
+
UNREAD_CONTENT_CONFIG_PATHS,
|
|
47
|
+
} from './content-config-ast'
|
|
48
|
+
export { createCmsCore } from './core'
|
|
49
|
+
export type { CmsCore, CmsCoreOptions } from './core'
|
|
50
|
+
export {
|
|
51
|
+
applyCreateRouteFields,
|
|
52
|
+
blankFieldValue,
|
|
53
|
+
blankRequiredFields,
|
|
54
|
+
type CollectionKind,
|
|
55
|
+
type CreateWriteField,
|
|
56
|
+
isBlankFieldValue,
|
|
57
|
+
newEntryFrontmatter,
|
|
58
|
+
newRepeaterItem,
|
|
59
|
+
normalizeCreateWrite,
|
|
60
|
+
omitEmptyOnCreate,
|
|
61
|
+
type RepeaterItemField,
|
|
62
|
+
type RequiredGuardField,
|
|
63
|
+
seedValueForRequiredField,
|
|
64
|
+
withoutBlankArrayItems,
|
|
65
|
+
type WriteModelField,
|
|
66
|
+
} from './editor-write-model'
|
|
67
|
+
export { globMayMatchUnder, globToRegExp, UnreadableDirectoryError } from './fs/glob'
|
|
68
|
+
export {
|
|
69
|
+
type CmsChangeset,
|
|
70
|
+
type CmsCommit,
|
|
71
|
+
CmsCommitConflictError,
|
|
72
|
+
type CmsFileVersion,
|
|
73
|
+
type CmsStagedChange,
|
|
74
|
+
commitChangeset,
|
|
75
|
+
createStagedFileSystem,
|
|
76
|
+
digestBytes,
|
|
77
|
+
type StagedFileSystem,
|
|
78
|
+
versionMatches,
|
|
79
|
+
versionOf,
|
|
80
|
+
} from './fs/staged'
|
|
81
|
+
export type { CmsFileSystem, GlobOptions } from './fs/types'
|
|
82
|
+
export {
|
|
83
|
+
type AddArrayItemInput,
|
|
84
|
+
type CreateEntryInput,
|
|
85
|
+
ensureMdxImports,
|
|
86
|
+
type EntryAsset,
|
|
87
|
+
type EntryOpsDeps,
|
|
88
|
+
type GetEntryResult,
|
|
89
|
+
parseFrontmatter,
|
|
90
|
+
type RemoveArrayItemInput,
|
|
91
|
+
serializeFrontmatter,
|
|
92
|
+
type UpdateEntryInput,
|
|
93
|
+
} from './handlers/entry-ops'
|
|
94
|
+
export {
|
|
95
|
+
type ContemberStorageOptions,
|
|
96
|
+
createContemberStorageAdapter,
|
|
97
|
+
createFileSystemStorageAdapter,
|
|
98
|
+
createS3StorageAdapter,
|
|
99
|
+
decodeFilteredMediaCursor,
|
|
100
|
+
type FileSystemStorageOptions,
|
|
101
|
+
getFileExtension,
|
|
102
|
+
isUnsafeFolder,
|
|
103
|
+
listFilteredMedia,
|
|
104
|
+
listProjectImages,
|
|
105
|
+
type ListProjectImagesOptions,
|
|
106
|
+
MEDIA_CURSOR_TYPE_MISMATCH,
|
|
107
|
+
MEDIA_INVALID_CURSOR,
|
|
108
|
+
MEDIA_INVALID_FOLDER,
|
|
109
|
+
MEDIA_INVALID_ID,
|
|
110
|
+
MEDIA_NOT_FOUND,
|
|
111
|
+
MediaCursorError,
|
|
112
|
+
mediaErrorStatus,
|
|
113
|
+
MIME_BY_EXT,
|
|
114
|
+
mimeFromExt,
|
|
115
|
+
parseMediaTypeFilter,
|
|
116
|
+
type S3StorageOptions,
|
|
117
|
+
uploadsDirRelativeToRoot,
|
|
118
|
+
} from './media/index'
|
|
119
|
+
export { parseProjectCmsConfig, parseProjectCmsConfigSource } from './project-config-ast'
|
|
120
|
+
export {
|
|
121
|
+
CLOUDFLARE_REDIRECT_LIMITS,
|
|
122
|
+
CMS_REDIRECTS_FILE,
|
|
123
|
+
type MergedRedirects,
|
|
124
|
+
mergeRedirects,
|
|
125
|
+
parseRedirectRule,
|
|
126
|
+
type RedirectLayer,
|
|
127
|
+
type RedirectLine,
|
|
128
|
+
type RedirectRuleLine,
|
|
129
|
+
} from './redirects'
|
|
130
|
+
export { type RouteCollectionScan, scanRouteCollections } from './route-scan'
|
|
131
|
+
export { describeIssue, type LiveIssue, type LiveParseResult, type LiveSchema, type LiveSchemas, schemaFor } from './schema-port'
|
|
132
|
+
export { acceptsMissing, firstAcceptedEntry, governsPath, pointAt, type ProbePoint, rejectsValueAt } from './schema-probe'
|
|
133
|
+
export {
|
|
134
|
+
applyDerivedTransform,
|
|
135
|
+
computeDerivedFieldUpdates,
|
|
136
|
+
computePathnameFromSpec,
|
|
137
|
+
type DerivedFieldSpec,
|
|
138
|
+
escapeHtml,
|
|
139
|
+
relativeImportPath,
|
|
140
|
+
resolvePathnameFromSpec,
|
|
141
|
+
slugify,
|
|
142
|
+
slugifyHref,
|
|
143
|
+
} from './shared'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { statSync } from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build a checker that decides whether a request URL maps to an existing file
|
|
6
|
+
* under Astro's `publicDir`. Used to bypass HTML rewriting for vendor pages
|
|
7
|
+
* whose inline scripts can be corrupted by injected markers or content-length
|
|
8
|
+
* mismatches.
|
|
9
|
+
*
|
|
10
|
+
* Cache lives for the dev server's lifetime; vendor HTML is essentially static,
|
|
11
|
+
* and the cache is cleared on restart.
|
|
12
|
+
*/
|
|
13
|
+
export function createPublicStaticFileChecker(publicDir: string | undefined): (urlPath: string) => boolean {
|
|
14
|
+
if (!publicDir) return () => false
|
|
15
|
+
const cache = new Map<string, boolean>()
|
|
16
|
+
|
|
17
|
+
return (urlPath: string) => {
|
|
18
|
+
const cleaned = urlPath.split('?')[0] || ''
|
|
19
|
+
if (!cleaned.startsWith('/') || cleaned.includes('..')) return false
|
|
20
|
+
|
|
21
|
+
const cached = cache.get(cleaned)
|
|
22
|
+
if (cached !== undefined) return cached
|
|
23
|
+
|
|
24
|
+
const candidates = [path.join(publicDir, cleaned)]
|
|
25
|
+
if (cleaned.endsWith('/')) {
|
|
26
|
+
candidates.push(path.join(publicDir, cleaned, 'index.html'))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let exists = false
|
|
30
|
+
for (const p of candidates) {
|
|
31
|
+
try {
|
|
32
|
+
if (statSync(p).isFile()) {
|
|
33
|
+
exists = true
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
} catch {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cache.set(cleaned, exists)
|
|
40
|
+
return exists
|
|
41
|
+
}
|
|
42
|
+
}
|