@fabrika/provider-zerops 0.0.21 → 0.0.22

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 (2) hide show
  1. package/package.json +5 -5
  2. package/src/control.ts +19 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/provider-zerops",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,9 +32,9 @@
32
32
  "gen:schema": "bun scripts/generate-zerops-types.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@fabrika/auth": "^0.0.21",
36
- "@fabrika/auth-core": "^0.0.21",
37
- "@fabrika/provider-contract": "^0.0.21",
38
- "@fabrika/proxy-contract": "^0.0.21"
35
+ "@fabrika/auth": "^0.0.22",
36
+ "@fabrika/auth-core": "^0.0.22",
37
+ "@fabrika/provider-contract": "^0.0.22",
38
+ "@fabrika/proxy-contract": "^0.0.22"
39
39
  }
40
40
  }
package/src/control.ts CHANGED
@@ -31,7 +31,9 @@ import {
31
31
  import { defaultSleep, defaultZeropsCollaborators, type Sleeper } from './collaborators'
32
32
  import {
33
33
  type FabrikaManifest,
34
+ manifestServiceHostnames,
34
35
  parseFabrikaManifest,
36
+ renderFabrikaImportYaml,
35
37
  renderFabrikaProvisioningYaml,
36
38
  verifyZeropsArtifactSourceDescriptor,
37
39
  zeropsArtifactCodec,
@@ -707,6 +709,7 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
707
709
  if (namespaceTarget.ready !== true || namespaceTarget.projectId === undefined) {
708
710
  throw new Error(`Zerops deployment namespace \`${namespace.id}\` is not ready`)
709
711
  }
712
+ const projectId = namespaceTarget.projectId
710
713
  const manifest = parseFabrikaManifest(
711
714
  decodeEnvelope('artifact', input.registration.environment.artifact, zeropsArtifactCodec),
712
715
  {
@@ -714,19 +717,29 @@ export const createZeropsControlProvider = (options: ZeropsControlProviderOption
714
717
  env: input.registration.environment.env,
715
718
  },
716
719
  )
720
+ const hostnames = manifestServiceHostnames(manifest)
721
+ const observed = await Promise.all(hostnames.map(async (hostname) => ({
722
+ hostname,
723
+ service: await api.findService({ projectId, hostname, signal: input.signal }),
724
+ })))
725
+ const present = observed.filter((entry) => entry.service !== null)
726
+ if (present.length !== 0 && present.length !== observed.length) {
727
+ throw new Error(`Zerops registration found only ${present.length} of ${observed.length} declared services`)
728
+ }
729
+ // startWithoutCode is safe only before the namespace contains an application service.
717
730
  const imported = await api.importServices({
718
- projectId: namespaceTarget.projectId,
719
- yaml: renderFabrikaProvisioningYaml(manifest),
731
+ projectId,
732
+ yaml: present.length === 0 ? renderFabrikaProvisioningYaml(manifest) : renderFabrikaImportYaml(manifest),
720
733
  signal: input.signal,
721
734
  })
722
735
  const reported = imported.services.find((service) => service.name === manifest.target.deployService)
723
- const discovered = reported === undefined
724
- ? await api.findService({
725
- projectId: namespaceTarget.projectId,
736
+ const observedDeployService = observed.find((entry) => entry.hostname === manifest.target.deployService)?.service
737
+ const discovered = reported ?? observedDeployService
738
+ ?? await api.findService({
739
+ projectId,
726
740
  hostname: manifest.target.deployService,
727
741
  signal: input.signal,
728
742
  })
729
- : reported
730
743
  if (discovered === null || discovered === undefined || discovered.id === '') {
731
744
  throw new Error(`Zerops import did not create deploy service \`${manifest.target.deployService}\``)
732
745
  }