@content-collections/core 0.10.0 → 0.11.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/index.d.ts CHANGED
@@ -60,7 +60,7 @@ declare const literalSchema: z__default.ZodUnion<[z__default.ZodString, z__defau
60
60
  type Literal = z__default.infer<typeof literalSchema>;
61
61
  type SchemaType = Literal | {
62
62
  [key: string]: SchemaType;
63
- } | SchemaType[];
63
+ } | ReadonlyArray<SchemaType>;
64
64
  type NotSerializableError = `The return type of the transform function must be an object serializable object.
65
65
  See https://www.content-collections.dev/docs/serialization for more information.
66
66
 
@@ -95,6 +95,11 @@ type Prettify<T> = {
95
95
  [K in keyof T]: T[K];
96
96
  } & {};
97
97
  type GetSchema<TCollection extends AnyCollection> = TCollection extends Collection<any, any, any, infer TSchema, any, any> ? Prettify<TSchema> : never;
98
+ declare const skippedSymbol: unique symbol;
99
+ type SkippedSignal = {
100
+ [skippedSymbol]: true;
101
+ reason?: string;
102
+ };
98
103
  type Context<TSchema = unknown> = {
99
104
  documents<TCollection extends AnyCollection>(collection: TCollection): Array<GetSchema<TCollection>>;
100
105
  cache: CacheFn;
@@ -103,6 +108,7 @@ type Context<TSchema = unknown> = {
103
108
  directory: string;
104
109
  documents: () => Promise<Array<TSchema>>;
105
110
  };
111
+ skip: (reason?: string) => SkippedSignal;
106
112
  };
107
113
  type Z = typeof z$1;
108
114
  type CollectionRequest<TName extends string, TShape extends TSchemaProp, TParser, TSchema, TTransformResult, TDocument> = {
@@ -130,7 +136,7 @@ type InvalidReturnType<TMessage extends string, TObject> = {
130
136
  type ResolveImports<TTransformResult> = TTransformResult extends Import<any> ? GetTypeOfImport<TTransformResult> : TTransformResult extends Array<infer U> ? Array<ResolveImports<U>> : TTransformResult extends (...args: any[]) => any ? TTransformResult : TTransformResult extends object ? {
131
137
  [K in keyof TTransformResult]: ResolveImports<TTransformResult[K]>;
132
138
  } : TTransformResult;
133
- declare function defineCollection<TName extends string, TShape extends TSchemaProp, TParser extends ConfiguredParser = "frontmatter", TSchema = Schema<TParser, TShape>, TTransformResult = never, TDocument = [TTransformResult] extends [never] ? Schema<TParser, TShape> : Awaited<TTransformResult>, TResult = TDocument extends Serializable ? Collection<TName, TShape, TParser, TSchema, TTransformResult, ResolveImports<TDocument>> : InvalidReturnType<NotSerializableError, TDocument>>(collection: CollectionRequest<TName, TShape, TParser, TSchema, TTransformResult, TDocument>): TResult;
139
+ declare function defineCollection<TName extends string, TShape extends TSchemaProp, TParser extends ConfiguredParser = "frontmatter", TSchema = Schema<TParser, TShape>, TTransformResult = never, TDocument = [TTransformResult] extends [never] ? Schema<TParser, TShape> : Exclude<Awaited<TTransformResult>, SkippedSignal>, TResult = TDocument extends Serializable ? Collection<TName, TShape, TParser, TSchema, TTransformResult, ResolveImports<TDocument>> : InvalidReturnType<NotSerializableError, TDocument>>(collection: CollectionRequest<TName, TShape, TParser, TSchema, TTransformResult, TDocument>): TResult;
134
140
  type Cache = "memory" | "file" | "none";
135
141
  type Configuration<TCollections extends Array<AnyCollection>> = {
136
142
  collections: TCollections;
@@ -187,6 +193,11 @@ type TransformerEvents = {
187
193
  collection: AnyCollection;
188
194
  error: TransformError;
189
195
  };
196
+ "transformer:document-skipped": {
197
+ collection: AnyCollection;
198
+ filePath: string;
199
+ reason?: string;
200
+ };
190
201
  };
191
202
  type ErrorType$1 = "Validation" | "Configuration" | "Transform" | "Result";
192
203
  declare class TransformError extends Error {
@@ -299,7 +310,7 @@ declare function createBuilder(configurationPath: string, options?: Options, emi
299
310
  unsubscribe: () => Promise<void>;
300
311
  }>;
301
312
  on: {
302
- <TKey extends "builder:start" | "builder:end" | "builder:created" | "watcher:file-changed" | "watcher:config-changed" | "watcher:config-reload-error" | "collector:read-error" | "collector:parse-error" | "transformer:validation-error" | "transformer:result-error" | "transformer:error" | "watcher:subscribe-error" | "watcher:subscribed" | "watcher:unsubscribed">(key: TKey, listener: (event: Events[TKey]) => void): void;
313
+ <TKey extends "builder:start" | "builder:end" | "builder:created" | "watcher:file-changed" | "watcher:config-changed" | "watcher:config-reload-error" | "collector:read-error" | "collector:parse-error" | "transformer:validation-error" | "transformer:result-error" | "transformer:error" | "transformer:document-skipped" | "watcher:subscribe-error" | "watcher:subscribed" | "watcher:unsubscribed">(key: TKey, listener: (event: Events[TKey]) => void): void;
303
314
  <TKey extends "_error" | "_all">(key: TKey, listener: (event: SystemEvents[TKey]) => void): void;
304
315
  };
305
316
  }>;
@@ -311,4 +322,4 @@ declare const deprecations: {
311
322
  type Deprecation = keyof typeof deprecations;
312
323
  declare function suppressDeprecatedWarnings(...deprecations: Array<Deprecation | "all">): void;
313
324
 
314
- export { type AnyCollection, type AnyConfiguration, type Builder, type BuilderEvents, CollectError, type Collection, type CollectionRequest, type Configuration, ConfigurationError, ConfigurationReloadError, type Context, type Document, type GetTypeByName, type Meta, type Modification, type Schema, TransformError, type Watcher, createBuilder, createDefaultImport, createNamedImport, defineCollection, defineConfig, defineParser, suppressDeprecatedWarnings };
325
+ export { type AnyCollection, type AnyConfiguration, type Builder, type BuilderEvents, CollectError, type Collection, type CollectionRequest, type Configuration, ConfigurationError, ConfigurationReloadError, type Context, type Document, type GetTypeByName, type Meta, type Modification, type Schema, type SkippedSignal, TransformError, type Watcher, createBuilder, createDefaultImport, createNamedImport, defineCollection, defineConfig, defineParser, skippedSymbol, suppressDeprecatedWarnings };
package/dist/index.js CHANGED
@@ -115,7 +115,7 @@ import { existsSync as existsSync2 } from "node:fs";
115
115
  import fs2 from "node:fs/promises";
116
116
  import path3 from "node:path";
117
117
 
118
- // ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.0/node_modules/bundle-require/dist/index.js
118
+ // ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.6/node_modules/bundle-require/dist/index.js
119
119
  import {
120
120
  build,
121
121
  context
@@ -292,7 +292,7 @@ var loadTsConfigInternal = (dir = process.cwd(), name = "tsconfig.json", isExten
292
292
  };
293
293
  var loadTsConfig = (dir, name) => loadTsConfigInternal(dir, name);
294
294
 
295
- // ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.0/node_modules/bundle-require/dist/index.js
295
+ // ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.6/node_modules/bundle-require/dist/index.js
296
296
  var tsconfigPathsToRegExp = (paths) => {
297
297
  return Object.keys(paths || {}).map((key) => {
298
298
  return new RegExp(`^${key.replace(/\*/, ".*")}$`);
@@ -693,12 +693,70 @@ function createSynchronizer(readCollectionFile, collections, baseDirectory = "."
693
693
 
694
694
  // src/transformer.ts
695
695
  import os from "node:os";
696
- import { basename, dirname as dirname2, extname } from "node:path";
696
+ import { basename, dirname as dirname2, extname, join as join3 } from "node:path";
697
697
  import pLimit from "p-limit";
698
698
 
699
+ // src/config.ts
700
+ import { z } from "zod";
701
+
702
+ // src/warn.ts
703
+ var deprecations = {
704
+ legacySchema: `The use of a function as a schema is deprecated.
705
+ Please use a StandardSchema compliant library directly.
706
+ For more information, see:
707
+ https://content-collections.dev/docs/deprecations/schema-as-function`
708
+ };
709
+ var _suppressDeprecatedWarnings = [];
710
+ function suppressDeprecatedWarnings(...deprecations2) {
711
+ for (const deprecation of deprecations2) {
712
+ if (deprecation === "all") {
713
+ _suppressDeprecatedWarnings.push(
714
+ ...Object.keys(deprecations2)
715
+ );
716
+ return;
717
+ } else {
718
+ _suppressDeprecatedWarnings.push(deprecation);
719
+ }
720
+ }
721
+ }
722
+ function warnDeprecated(deprecation, logger = console.warn) {
723
+ if (_suppressDeprecatedWarnings.includes(deprecation)) {
724
+ return;
725
+ }
726
+ logger(`[CC DEPRECATED]: ${deprecations[deprecation]}`);
727
+ }
728
+
729
+ // src/config.ts
730
+ var skippedSymbol = Symbol("skipped");
731
+ var InvalidReturnTypeSymbol = Symbol(`InvalidReturnType`);
732
+ function defineCollection(collection) {
733
+ let typeName = collection.typeName;
734
+ if (!typeName) {
735
+ typeName = generateTypeName(collection.name);
736
+ }
737
+ let parser = collection.parser;
738
+ if (!parser) {
739
+ parser = "frontmatter";
740
+ }
741
+ let schema2 = collection.schema;
742
+ if (!schema2["~standard"]) {
743
+ warnDeprecated("legacySchema");
744
+ schema2 = z.object(schema2(z));
745
+ }
746
+ return {
747
+ ...collection,
748
+ typeName,
749
+ parser,
750
+ schema: schema2
751
+ };
752
+ }
753
+ function defineConfig(config) {
754
+ return config;
755
+ }
756
+
699
757
  // src/serializer.ts
700
758
  import serializeJs from "serialize-javascript";
701
- import z from "zod";
759
+ import z2 from "zod";
702
760
 
703
761
  // src/import.ts
704
762
  var importSymbol = Symbol("import");
@@ -720,24 +778,24 @@ function createNamedImport(name, path10) {
720
778
  }
721
779
 
722
780
  // src/serializer.ts
723
- var literalSchema = z.union([
781
+ var literalSchema = z2.union([
724
782
  // json
725
- z.string(),
726
- z.number(),
727
- z.boolean(),
728
- z.null(),
783
+ z2.string(),
784
+ z2.number(),
785
+ z2.boolean(),
786
+ z2.null(),
729
787
  // serializable-javascript
730
- z.undefined(),
731
- z.date(),
732
- z.map(z.unknown(), z.unknown()),
733
- z.set(z.unknown()),
734
- z.bigint()
788
+ z2.undefined(),
789
+ z2.date(),
790
+ z2.map(z2.unknown(), z2.unknown()),
791
+ z2.set(z2.unknown()),
792
+ z2.bigint()
735
793
  ]);
736
- var schema = z.lazy(
737
- () => z.union([literalSchema, z.array(schema), z.record(schema)])
794
+ var schema = z2.lazy(
795
+ () => z2.union([literalSchema, z2.array(schema), z2.record(schema)])
738
796
  );
739
797
  var extension = "js";
740
- var serializableSchema = z.record(schema);
798
+ var serializableSchema = z2.record(schema);
741
799
  function createImport(imp, variableName) {
742
800
  const variableDeclaration = imp.name ? `{ ${imp.name} as ${variableName} }` : variableName;
743
801
  return `import ${variableDeclaration} from "${imp.path}";
@@ -781,6 +839,9 @@ var TransformError = class extends Error {
781
839
  this.type = type;
782
840
  }
783
841
  };
842
+ function isSkippedSignal(signal) {
843
+ return signal[skippedSymbol] === true;
844
+ }
784
845
  function createPath(path10, ext) {
785
846
  let p = path10.slice(0, -ext.length);
786
847
  if (p.endsWith("/index")) {
@@ -872,7 +933,11 @@ function createTransformer(emitter, cacheManager) {
872
933
  return collection.documents.map((doc) => doc.document);
873
934
  }
874
935
  },
875
- cache: cache.cacheFn
936
+ cache: cache.cacheFn,
937
+ skip: (reason) => ({
938
+ [skippedSymbol]: true,
939
+ reason
940
+ })
876
941
  };
877
942
  }
878
943
  async function transformDocument(collections, collection, transform, doc) {
@@ -881,10 +946,18 @@ function createTransformer(emitter, cacheManager) {
881
946
  try {
882
947
  const document = await transform(doc.document, context2);
883
948
  await cache.tidyUp();
884
- return {
885
- ...doc,
886
- document
887
- };
949
+ if (isSkippedSignal(document)) {
950
+ emitter.emit("transformer:document-skipped", {
951
+ collection,
952
+ filePath: join3(collection.directory, doc.document._meta.filePath),
953
+ reason: document.reason
954
+ });
955
+ } else {
956
+ return {
957
+ ...doc,
958
+ document
959
+ };
960
+ }
888
961
  } catch (error) {
889
962
  if (error instanceof TransformError) {
890
963
  emitter.emit("transformer:error", {
@@ -1283,63 +1356,6 @@ async function createBuilder(configurationPath, options = {
1283
1356
  on: emitter.on
1284
1357
  };
1285
1358
  }
1286
-
1287
- // src/config.ts
1288
- import { z as z2 } from "zod";
1289
-
1290
- // src/warn.ts
1291
- var deprecations = {
1292
- legacySchema: `The use of a function as a schema is deprecated.
1293
- Please use a StandardSchema compliant library directly.
1294
- For more information, see:
1295
- https://content-collections.dev/docs/deprecations/schema-as-function`
1296
- };
1297
- var _suppressDeprecatedWarnings = [];
1298
- function suppressDeprecatedWarnings(...deprecations2) {
1299
- for (const deprecation of deprecations2) {
1300
- if (deprecation === "all") {
1301
- _suppressDeprecatedWarnings.push(
1302
- ...Object.keys(deprecations2)
1303
- );
1304
- return;
1305
- } else {
1306
- _suppressDeprecatedWarnings.push(deprecation);
1307
- }
1308
- }
1309
- }
1310
- function warnDeprecated(deprecation, logger = console.warn) {
1311
- if (_suppressDeprecatedWarnings.includes(deprecation)) {
1312
- return;
1313
- }
1314
- logger(`[CC DEPRECATED]: ${deprecations[deprecation]}`);
1315
- }
1316
-
1317
- // src/config.ts
1318
- var InvalidReturnTypeSymbol = Symbol(`InvalidReturnType`);
1319
- function defineCollection(collection) {
1320
- let typeName = collection.typeName;
1321
- if (!typeName) {
1322
- typeName = generateTypeName(collection.name);
1323
- }
1324
- let parser = collection.parser;
1325
- if (!parser) {
1326
- parser = "frontmatter";
1327
- }
1328
- let schema2 = collection.schema;
1329
- if (!schema2["~standard"]) {
1330
- warnDeprecated("legacySchema");
1331
- schema2 = z2.object(schema2(z2));
1332
- }
1333
- return {
1334
- ...collection,
1335
- typeName,
1336
- parser,
1337
- schema: schema2
1338
- };
1339
- }
1340
- function defineConfig(config) {
1341
- return config;
1342
- }
1343
1359
  export {
1344
1360
  CollectError,
1345
1361
  ConfigurationError,
@@ -1351,5 +1367,6 @@ export {
1351
1367
  defineCollection,
1352
1368
  defineConfig,
1353
1369
  defineParser,
1370
+ skippedSymbol,
1354
1371
  suppressDeprecatedWarnings
1355
1372
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@content-collections/core",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.11.0",
5
5
  "description": "Core of Content Collections",
6
6
  "author": "Sebastian Sdorra <s.sdorra@gmail.com>",
7
7
  "license": "MIT",
@@ -33,12 +33,12 @@
33
33
  "@types/picomatch": "^3.0.1",
34
34
  "@types/pluralize": "^0.0.33",
35
35
  "@types/serialize-javascript": "^5.0.4",
36
- "@vitest/coverage-v8": "^3.1.3",
36
+ "@vitest/coverage-v8": "^3.2.4",
37
37
  "bundle-require": "^5.0.0",
38
38
  "tsup": "^8.2.4",
39
39
  "tsx": "^4.19.2",
40
40
  "typescript": "^5.5.4",
41
- "vitest": "^3.1.3"
41
+ "vitest": "^3.2.4"
42
42
  },
43
43
  "dependencies": {
44
44
  "@standard-schema/spec": "^1.0.0",
@@ -57,6 +57,6 @@
57
57
  "scripts": {
58
58
  "build": "tsup src/index.ts --format esm --dts -d dist",
59
59
  "typecheck": "tsc",
60
- "test": "vitest --run --coverage"
60
+ "test": "vitest --run --coverage --typecheck"
61
61
  }
62
62
  }