Skip to content

Commit

Permalink
Merge branch 'maps/proxied_format' of github.com:thomasneirynck/kiban…
Browse files Browse the repository at this point in the history
…a into maps/proxied_format
  • Loading branch information
thomasneirynck committed Oct 7, 2020
2 parents b2d76a3 + 9a47be6 commit 5664f3c
Show file tree
Hide file tree
Showing 82 changed files with 919 additions and 391 deletions.
7 changes: 4 additions & 3 deletions docs/api/saved-objects/bulk_create.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ experimental[] Create multiple {kib} saved objects.
`references`::
(Optional, array) Objects with `name`, `id`, and `type` properties that describe the other saved objects in the referenced object. To refer to the other saved object, use `name` in the attributes. Never use `id` to refer to the other saved object. `id` can be automatically updated during migrations, import, or export.

`namespaces`::
(Optional, string array) Identifiers for the <<xpack-spaces,spaces>> in which this object should be created. If this is not provided, the
object will be created in the current space.
`initialNamespaces`::
(Optional, string array) Identifiers for the <<xpack-spaces,spaces>> in which this object is created. If this is provided, the
object is created only in the explicitly defined spaces. If this is not provided, the object is created in the current space
(default behavior).

`version`::
(Optional, number) Specifies the version.
Expand Down
7 changes: 4 additions & 3 deletions docs/api/saved-objects/create.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ any data that you send to the API is properly formed.
`references`::
(Optional, array) Objects with `name`, `id`, and `type` properties that describe the other saved objects that this object references. Use `name` in attributes to refer to the other saved object, but never the `id`, which can update automatically during migrations or import/export.

`namespaces`::
(Optional, string array) Identifiers for the <<xpack-spaces,spaces>> in which this object should be created. If this is not provided, the
object will be created in the current space.
`initialNamespaces`::
(Optional, string array) Identifiers for the <<xpack-spaces,spaces>> in which this object is created. If this is provided, the
object is created only in the explicitly defined spaces. If this is not provided, the object is created in the current space
(default behavior).

[[saved-objects-api-create-request-codes]]
==== Response code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsBulkCreateObject](./kibana-plugin-core-server.savedobjectsbulkcreateobject.md) &gt; [namespaces](./kibana-plugin-core-server.savedobjectsbulkcreateobject.namespaces.md)
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsBulkCreateObject](./kibana-plugin-core-server.savedobjectsbulkcreateobject.md) &gt; [initialNamespaces](./kibana-plugin-core-server.savedobjectsbulkcreateobject.initialnamespaces.md)

## SavedObjectsBulkCreateObject.namespaces property
## SavedObjectsBulkCreateObject.initialNamespaces property

Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.

Expand All @@ -11,5 +11,5 @@ Note: this can only be used for multi-namespace object types.
<b>Signature:</b>

```typescript
namespaces?: string[];
initialNamespaces?: string[];
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface SavedObjectsBulkCreateObject<T = unknown>
| --- | --- | --- |
| [attributes](./kibana-plugin-core-server.savedobjectsbulkcreateobject.attributes.md) | <code>T</code> | |
| [id](./kibana-plugin-core-server.savedobjectsbulkcreateobject.id.md) | <code>string</code> | |
| [initialNamespaces](./kibana-plugin-core-server.savedobjectsbulkcreateobject.initialnamespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [migrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [namespaces](./kibana-plugin-core-server.savedobjectsbulkcreateobject.namespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [originId](./kibana-plugin-core-server.savedobjectsbulkcreateobject.originid.md) | <code>string</code> | Optional ID of the original saved object, if this object's <code>id</code> was regenerated |
| [references](./kibana-plugin-core-server.savedobjectsbulkcreateobject.references.md) | <code>SavedObjectReference[]</code> | |
| [type](./kibana-plugin-core-server.savedobjectsbulkcreateobject.type.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md) &gt; [namespaces](./kibana-plugin-core-server.savedobjectscreateoptions.namespaces.md)
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md) &gt; [initialNamespaces](./kibana-plugin-core-server.savedobjectscreateoptions.initialnamespaces.md)

## SavedObjectsCreateOptions.namespaces property
## SavedObjectsCreateOptions.initialNamespaces property

Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.

Expand All @@ -11,5 +11,5 @@ Note: this can only be used for multi-namespace object types.
<b>Signature:</b>

```typescript
namespaces?: string[];
initialNamespaces?: string[];
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions
| Property | Type | Description |
| --- | --- | --- |
| [id](./kibana-plugin-core-server.savedobjectscreateoptions.id.md) | <code>string</code> | (not recommended) Specify an id for the document |
| [initialNamespaces](./kibana-plugin-core-server.savedobjectscreateoptions.initialnamespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [migrationVersion](./kibana-plugin-core-server.savedobjectscreateoptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [namespaces](./kibana-plugin-core-server.savedobjectscreateoptions.namespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [originId](./kibana-plugin-core-server.savedobjectscreateoptions.originid.md) | <code>string</code> | Optional ID of the original saved object, if this object's <code>id</code> was regenerated |
| [overwrite](./kibana-plugin-core-server.savedobjectscreateoptions.overwrite.md) | <code>boolean</code> | Overwrite existing documents (defaults to false) |
| [references](./kibana-plugin-core-server.savedobjectscreateoptions.references.md) | <code>SavedObjectReference[]</code> | |
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/routes/bulk_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const registerBulkCreateRoute = (router: IRouter) => {
})
)
),
namespaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })),
initialNamespaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })),
})
),
},
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export const registerCreateRoute = (router: IRouter) => {
})
)
),
namespaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })),
initialNamespaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })),
}),
},
},
router.handleLegacyErrors(async (context, req, res) => {
const { type, id } = req.params;
const { overwrite } = req.query;
const { attributes, migrationVersion, references, namespaces } = req.body;
const { attributes, migrationVersion, references, initialNamespaces } = req.body;

const options = { id, overwrite, migrationVersion, references, namespaces };
const options = { id, overwrite, migrationVersion, references, initialNamespaces };
const result = await context.core.savedObjects.client.create(type, attributes, options);
return res.ok({ body: result });
})
Expand Down
38 changes: 20 additions & 18 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,13 @@ describe('SavedObjectsRepository', () => {
await test(namespace);
});

it(`adds namespaces instead of namespace`, async () => {
it(`adds initialNamespaces instead of namespace`, async () => {
const test = async (namespace) => {
const ns2 = 'bar-namespace';
const ns3 = 'baz-namespace';
const objects = [
{ ...obj1, type: MULTI_NAMESPACE_TYPE, namespaces: [ns2] },
{ ...obj2, type: MULTI_NAMESPACE_TYPE, namespaces: [ns3] },
{ ...obj1, type: MULTI_NAMESPACE_TYPE, initialNamespaces: [ns2] },
{ ...obj2, type: MULTI_NAMESPACE_TYPE, initialNamespaces: [ns3] },
];
await bulkCreateSuccess(objects, { namespace, overwrite: true });
const body = [
Expand Down Expand Up @@ -758,30 +758,30 @@ describe('SavedObjectsRepository', () => {
).rejects.toThrowError(createBadRequestError('"options.namespace" cannot be "*"'));
});

it(`returns error when namespaces is used with a non-multi-namespace object`, async () => {
it(`returns error when initialNamespaces is used with a non-multi-namespace object`, async () => {
const test = async (objType) => {
const obj = { ...obj3, type: objType, namespaces: [] };
const obj = { ...obj3, type: objType, initialNamespaces: [] };
await bulkCreateError(
obj,
undefined,
expectErrorResult(
obj,
createBadRequestError('"namespaces" can only be used on multi-namespace types')
createBadRequestError('"initialNamespaces" can only be used on multi-namespace types')
)
);
};
await test('dashboard');
await test(NAMESPACE_AGNOSTIC_TYPE);
});

it(`throws when options.namespaces is used with a multi-namespace type and is empty`, async () => {
const obj = { ...obj3, type: MULTI_NAMESPACE_TYPE, namespaces: [] };
it(`throws when options.initialNamespaces is used with a multi-namespace type and is empty`, async () => {
const obj = { ...obj3, type: MULTI_NAMESPACE_TYPE, initialNamespaces: [] };
await bulkCreateError(
obj,
undefined,
expectErrorResult(
obj,
createBadRequestError('"namespaces" must be a non-empty array of strings')
createBadRequestError('"initialNamespaces" must be a non-empty array of strings')
)
);
});
Expand Down Expand Up @@ -1993,13 +1993,13 @@ describe('SavedObjectsRepository', () => {
);
});

it(`adds namespaces instead of namespace`, async () => {
const options = { id, namespace, namespaces: ['bar-namespace', 'baz-namespace'] };
it(`adds initialNamespaces instead of namespace`, async () => {
const options = { id, namespace, initialNamespaces: ['bar-namespace', 'baz-namespace'] };
await createSuccess(MULTI_NAMESPACE_TYPE, attributes, options);
expect(client.create).toHaveBeenCalledWith(
expect.objectContaining({
id: `${MULTI_NAMESPACE_TYPE}:${id}`,
body: expect.objectContaining({ namespaces: options.namespaces }),
body: expect.objectContaining({ namespaces: options.initialNamespaces }),
}),
expect.anything()
);
Expand All @@ -2021,23 +2021,25 @@ describe('SavedObjectsRepository', () => {
});

describe('errors', () => {
it(`throws when options.namespaces is used with a non-multi-namespace object`, async () => {
it(`throws when options.initialNamespaces is used with a non-multi-namespace object`, async () => {
const test = async (objType) => {
await expect(
savedObjectsRepository.create(objType, attributes, { namespaces: [namespace] })
savedObjectsRepository.create(objType, attributes, { initialNamespaces: [namespace] })
).rejects.toThrowError(
createBadRequestError('"options.namespaces" can only be used on multi-namespace types')
createBadRequestError(
'"options.initialNamespaces" can only be used on multi-namespace types'
)
);
};
await test('dashboard');
await test(NAMESPACE_AGNOSTIC_TYPE);
});

it(`throws when options.namespaces is used with a multi-namespace type and is empty`, async () => {
it(`throws when options.initialNamespaces is used with a multi-namespace type and is empty`, async () => {
await expect(
savedObjectsRepository.create(MULTI_NAMESPACE_TYPE, attributes, { namespaces: [] })
savedObjectsRepository.create(MULTI_NAMESPACE_TYPE, attributes, { initialNamespaces: [] })
).rejects.toThrowError(
createBadRequestError('"options.namespaces" must be a non-empty array of strings')
createBadRequestError('"options.initialNamespaces" must be a non-empty array of strings')
);
});

Expand Down
28 changes: 14 additions & 14 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ export class SavedObjectsRepository {
references = [],
refresh = DEFAULT_REFRESH_SETTING,
originId,
namespaces,
initialNamespaces,
version,
} = options;
const namespace = normalizeNamespace(options.namespace);

if (namespaces) {
if (initialNamespaces) {
if (!this._registry.isMultiNamespace(type)) {
throw SavedObjectsErrorHelpers.createBadRequestError(
'"options.namespaces" can only be used on multi-namespace types'
'"options.initialNamespaces" can only be used on multi-namespace types'
);
} else if (!namespaces.length) {
} else if (!initialNamespaces.length) {
throw SavedObjectsErrorHelpers.createBadRequestError(
'"options.namespaces" must be a non-empty array of strings'
'"options.initialNamespaces" must be a non-empty array of strings'
);
}
}
Expand All @@ -262,9 +262,9 @@ export class SavedObjectsRepository {
// we will overwrite a multi-namespace saved object if it exists; if that happens, ensure we preserve its included namespaces
// note: this check throws an error if the object is found but does not exist in this namespace
const existingNamespaces = await this.preflightGetNamespaces(type, id, namespace);
savedObjectNamespaces = namespaces || existingNamespaces;
savedObjectNamespaces = initialNamespaces || existingNamespaces;
} else {
savedObjectNamespaces = namespaces || getSavedObjectNamespaces(namespace);
savedObjectNamespaces = initialNamespaces || getSavedObjectNamespaces(namespace);
}
}

Expand Down Expand Up @@ -323,14 +323,14 @@ export class SavedObjectsRepository {
let error: DecoratedError | undefined;
if (!this._allowedTypes.includes(object.type)) {
error = SavedObjectsErrorHelpers.createUnsupportedTypeError(object.type);
} else if (object.namespaces) {
} else if (object.initialNamespaces) {
if (!this._registry.isMultiNamespace(object.type)) {
error = SavedObjectsErrorHelpers.createBadRequestError(
'"namespaces" can only be used on multi-namespace types'
'"initialNamespaces" can only be used on multi-namespace types'
);
} else if (!object.namespaces.length) {
} else if (!object.initialNamespaces.length) {
error = SavedObjectsErrorHelpers.createBadRequestError(
'"namespaces" must be a non-empty array of strings'
'"initialNamespaces" must be a non-empty array of strings'
);
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ export class SavedObjectsRepository {
let versionProperties;
const {
esRequestIndex,
object: { namespaces, version, ...object },
object: { initialNamespaces, version, ...object },
method,
} = expectedBulkGetResult.value;
if (esRequestIndex !== undefined) {
Expand All @@ -410,13 +410,13 @@ export class SavedObjectsRepository {
};
}
savedObjectNamespaces =
namespaces || getSavedObjectNamespaces(namespace, docFound && actualResult);
initialNamespaces || getSavedObjectNamespaces(namespace, docFound && actualResult);
versionProperties = getExpectedVersionProperties(version, actualResult);
} else {
if (this._registry.isSingleNamespace(object.type)) {
savedObjectNamespace = namespace;
} else if (this._registry.isMultiNamespace(object.type)) {
savedObjectNamespaces = namespaces || getSavedObjectNamespaces(namespace);
savedObjectNamespaces = initialNamespaces || getSavedObjectNamespaces(namespace);
}
versionProperties = getExpectedVersionProperties(version);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/service/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
*
* Note: this can only be used for multi-namespace object types.
*/
namespaces?: string[];
initialNamespaces?: string[];
}

/**
Expand All @@ -79,7 +79,7 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
*
* Note: this can only be used for multi-namespace object types.
*/
namespaces?: string[];
initialNamespaces?: string[];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1936,8 +1936,8 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
attributes: T;
// (undocumented)
id?: string;
initialNamespaces?: string[];
migrationVersion?: SavedObjectsMigrationVersion;
namespaces?: string[];
originId?: string;
// (undocumented)
references?: SavedObjectReference[];
Expand Down Expand Up @@ -2094,8 +2094,8 @@ export interface SavedObjectsCoreFieldMapping {
// @public (undocumented)
export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
id?: string;
initialNamespaces?: string[];
migrationVersion?: SavedObjectsMigrationVersion;
namespaces?: string[];
originId?: string;
overwrite?: boolean;
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion src/dev/typescript/build_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function buildAllRefs(log: ToolingLog) {
async function buildRefs(log: ToolingLog, projectPath: string) {
try {
log.debug(`Building TypeScript projects refs for ${projectPath}...`);
await execa(require.resolve('typescript/bin/tsc'), ['-b', projectPath]);
await execa(require.resolve('typescript/bin/tsc'), ['-b', projectPath, '--pretty']);
} catch (e) {
log.error(e);
process.exit(1);
Expand Down
Loading

0 comments on commit 5664f3c

Please sign in to comment.