@elek-io/core 0.6.0 → 0.7.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.
@@ -136,13 +136,13 @@ var baseFileSchema = z2.object({
136
136
  */
137
137
  id: uuidSchema.readonly(),
138
138
  /**
139
- * The timestamp of the file being created is set by the service of "objectType" while creating it
139
+ * The datetime of the file being created is set by the service of "objectType" while creating it
140
140
  */
141
- created: z2.number().readonly(),
141
+ created: z2.string().datetime().readonly(),
142
142
  /**
143
- * The timestamp of the file being updated is set by the service of "objectType" while updating it
143
+ * The datetime of the file being updated is set by the service of "objectType" while updating it
144
144
  */
145
- updated: z2.number().nullable()
145
+ updated: z2.string().datetime().nullable()
146
146
  });
147
147
  var baseFileWithLanguageSchema = baseFileSchema.extend({
148
148
  /**
@@ -662,7 +662,7 @@ var gitCommitSchema = z8.object({
662
662
  hash: z8.string(),
663
663
  message: z8.string(),
664
664
  author: gitSignatureSchema,
665
- timestamp: z8.number(),
665
+ datetime: z8.string().datetime(),
666
666
  tag: z8.string().nullable()
667
667
  });
668
668
  var GitCommitIconNative = /* @__PURE__ */ ((GitCommitIconNative2) => {
@@ -731,7 +731,7 @@ var gitTagSchema = z9.object({
731
731
  id: uuidSchema,
732
732
  message: z9.string(),
733
733
  author: gitSignatureSchema,
734
- timestamp: z9.number()
734
+ datetime: z9.string().datetime()
735
735
  });
736
736
  var createGitTagSchema = gitTagSchema.pick({
737
737
  message: true
@@ -1188,24 +1188,22 @@ import Fs2 from "fs-extra";
1188
1188
  import isSvg from "is-svg";
1189
1189
 
1190
1190
  // src/util/shared.ts
1191
- import slugify from "slugify";
1191
+ import slugify from "@sindresorhus/slugify";
1192
1192
  import { v4 as generateUuid } from "uuid";
1193
- var Slugify = slugify.default || slugify;
1194
1193
  function uuid() {
1195
1194
  return generateUuid();
1196
1195
  }
1197
- function currentTimestamp() {
1198
- return Math.floor(Date.now() / 1e3);
1196
+ function datetime(value) {
1197
+ if (!value) {
1198
+ return (/* @__PURE__ */ new Date()).toISOString();
1199
+ }
1200
+ return new Date(value).toISOString();
1199
1201
  }
1200
1202
  function slug(string) {
1201
- return Slugify(string, {
1202
- replacement: "-",
1203
- // replace spaces with replacement character, defaults to `-`
1204
- // remove: undefined, // remove characters that match regex, defaults to `undefined`
1205
- lower: true,
1206
- // convert to lower case, defaults to `false`
1207
- strict: true
1208
- // strip special characters except replacement, defaults to `false`
1203
+ return slugify(string, {
1204
+ separator: "-",
1205
+ lowercase: true,
1206
+ decamelize: true
1209
1207
  });
1210
1208
  }
1211
1209
 
@@ -1238,7 +1236,7 @@ var AssetService = class extends AbstractCrudService {
1238
1236
  ...props,
1239
1237
  objectType: "asset",
1240
1238
  id,
1241
- created: currentTimestamp(),
1239
+ created: datetime(),
1242
1240
  updated: null,
1243
1241
  extension: fileType.extension,
1244
1242
  mimeType: fileType.mimeType,
@@ -1287,7 +1285,7 @@ var AssetService = class extends AbstractCrudService {
1287
1285
  const assetFile = {
1288
1286
  ...prevAssetFile,
1289
1287
  ...props,
1290
- updated: currentTimestamp()
1288
+ updated: datetime()
1291
1289
  };
1292
1290
  if (props.newFilePath) {
1293
1291
  const fileType = await this.getSupportedFileTypeOrThrow(
@@ -1462,7 +1460,7 @@ var CollectionService = class extends AbstractCrudService {
1462
1460
  singular: slug(props.slug.singular),
1463
1461
  plural: slug(props.slug.plural)
1464
1462
  },
1465
- created: currentTimestamp(),
1463
+ created: datetime(),
1466
1464
  updated: null
1467
1465
  };
1468
1466
  await Fs3.ensureDir(collectionPath);
@@ -1504,7 +1502,7 @@ var CollectionService = class extends AbstractCrudService {
1504
1502
  const collectionFile = {
1505
1503
  ...prevCollectionFile,
1506
1504
  ...props,
1507
- updated: currentTimestamp()
1505
+ updated: datetime()
1508
1506
  };
1509
1507
  await this.jsonFileService.update(
1510
1508
  collectionFile,
@@ -1606,7 +1604,7 @@ var EntryService = class extends AbstractCrudService {
1606
1604
  objectType: "entry",
1607
1605
  id,
1608
1606
  values: props.values,
1609
- created: currentTimestamp(),
1607
+ created: datetime(),
1610
1608
  updated: null
1611
1609
  };
1612
1610
  const entry = await this.toEntry({
@@ -1666,7 +1664,7 @@ var EntryService = class extends AbstractCrudService {
1666
1664
  const entryFile = {
1667
1665
  ...prevEntryFile,
1668
1666
  values: props.values,
1669
- updated: currentTimestamp()
1667
+ updated: datetime()
1670
1668
  };
1671
1669
  const entry = await this.toEntry({
1672
1670
  projectId: props.projectId,
@@ -1947,7 +1945,7 @@ var GitTagService = class extends AbstractCrudService {
1947
1945
  /**
1948
1946
  * Gets all local tags or filter them by pattern
1949
1947
  *
1950
- * They are sorted by authordate of the commit, not the timestamp the tag is created.
1948
+ * They are sorted by authordate of the commit, not when the tag is created.
1951
1949
  * This ensures tags are sorted correctly in the timeline of their commits.
1952
1950
  *
1953
1951
  * @see https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list
@@ -1958,7 +1956,7 @@ var GitTagService = class extends AbstractCrudService {
1958
1956
  args = [
1959
1957
  ...args,
1960
1958
  "--sort=-*authordate",
1961
- "--format=%(refname:short)|%(subject)|%(*authorname)|%(*authoremail)|%(*authordate:unix)"
1959
+ "--format=%(refname:short)|%(subject)|%(*authorname)|%(*authoremail)|%(*authordate:iso-strict)"
1962
1960
  ];
1963
1961
  const result = await this.git(props.path, args);
1964
1962
  const noEmptyLinesArr = result.stdout.split(EOL).filter((line) => {
@@ -1973,7 +1971,7 @@ var GitTagService = class extends AbstractCrudService {
1973
1971
  name: lineArray[2],
1974
1972
  email: lineArray[3]
1975
1973
  },
1976
- timestamp: parseInt(lineArray[4] || "")
1974
+ datetime: datetime(lineArray[4])
1977
1975
  };
1978
1976
  });
1979
1977
  const gitTags = lineObjArr.filter(this.isGitTag.bind(this));
@@ -2337,7 +2335,7 @@ var GitService = class {
2337
2335
  }
2338
2336
  const result = await this.git(path, [
2339
2337
  ...args,
2340
- "--format=%H|%s|%an|%ae|%at|%D"
2338
+ "--format=%H|%s|%an|%ae|%aI|%D"
2341
2339
  ]);
2342
2340
  const noEmptyLinesArr = result.stdout.split(EOL2).filter((line) => {
2343
2341
  return line.trim() !== "";
@@ -2351,7 +2349,7 @@ var GitService = class {
2351
2349
  name: lineArray[2],
2352
2350
  email: lineArray[3]
2353
2351
  },
2354
- timestamp: parseInt(lineArray[4] || ""),
2352
+ datetime: datetime(lineArray[4]),
2355
2353
  tag: this.refNameToTagName(lineArray[5] || "")
2356
2354
  };
2357
2355
  });
@@ -2364,62 +2362,6 @@ var GitService = class {
2364
2362
  }
2365
2363
  return tagName;
2366
2364
  }
2367
- /**
2368
- * Returns a timestamp of given files creation
2369
- *
2370
- * Git only returns the timestamp the file was added,
2371
- * which could be different from the file being created.
2372
- * But since file operations will always be committed
2373
- * immediately, this is practically the same.
2374
- *
2375
- * @param path Path to the repository
2376
- * @param file File to get timestamp from
2377
- */
2378
- async getFileCreatedTimestamp(path, file) {
2379
- const result = await this.git(path, [
2380
- "log",
2381
- "--diff-filter=A",
2382
- "--follow",
2383
- "--format=%at",
2384
- "--max-count=1",
2385
- "--",
2386
- file
2387
- ]);
2388
- return parseInt(result.stdout);
2389
- }
2390
- /**
2391
- * Returns a timestamp of the files last modification
2392
- *
2393
- * @param path Path to the repository
2394
- * @param file File to get timestamp from
2395
- */
2396
- async getFileLastUpdatedTimestamp(path, file) {
2397
- const result = await this.git(path, [
2398
- "log",
2399
- "--follow",
2400
- "--format=%at",
2401
- "--max-count=1",
2402
- "--",
2403
- file
2404
- ]);
2405
- return parseInt(result.stdout);
2406
- }
2407
- /**
2408
- * Returns created and updated timestamps from given file
2409
- *
2410
- * @param path Path to the project
2411
- * @param file Path to the file
2412
- */
2413
- async getFileCreatedUpdatedMeta(path, file) {
2414
- const meta = await Promise.all([
2415
- this.getFileCreatedTimestamp(path, file),
2416
- this.getFileLastUpdatedTimestamp(path, file)
2417
- ]);
2418
- return {
2419
- created: meta[0],
2420
- updated: meta[1]
2421
- };
2422
- }
2423
2365
  /**
2424
2366
  * Reads the currently used version of Git
2425
2367
  *
@@ -2643,7 +2585,7 @@ var ProjectService = class extends AbstractCrudService {
2643
2585
  id,
2644
2586
  description: props.description || "",
2645
2587
  settings: Object.assign({}, defaultSettings, props.settings),
2646
- created: currentTimestamp(),
2588
+ created: datetime(),
2647
2589
  updated: null,
2648
2590
  coreVersion: this.options.version,
2649
2591
  // @todo should be read from package.json to avoid duplicates
@@ -2735,7 +2677,7 @@ var ProjectService = class extends AbstractCrudService {
2735
2677
  default: props.settings?.language.default || prevProjectFile.settings.language.default
2736
2678
  }
2737
2679
  },
2738
- updated: currentTimestamp()
2680
+ updated: datetime()
2739
2681
  };
2740
2682
  await this.jsonFileService.update(projectFile, filePath, projectFileSchema);
2741
2683
  await this.gitService.add(projectPath, [filePath]);
@@ -3182,8 +3124,8 @@ export {
3182
3124
  createGitTagSchema,
3183
3125
  createProjectSchema,
3184
3126
  currentBranchProjectSchema,
3185
- currentTimestamp,
3186
3127
  dateValueDefinitionSchema,
3128
+ datetime,
3187
3129
  datetimeValueDefinitionSchema,
3188
3130
  ElekIoCore as default,
3189
3131
  deleteAssetSchema,